From 4390be9d7288041bcb5716292001c634f2b7d976 Mon Sep 17 00:00:00 2001 From: darthsandmann Date: Thu, 11 Aug 2022 21:07:23 +0200 Subject: [PATCH] Updates --- packages/button/button_logic.yaml | 118 ++++++++++------- packages/climate/weather.yaml | 26 ++-- packages/homeassistant/homeassistant.yaml | 1 - .../homeassistant/notification_summary.yaml | 5 +- packages/homeassistant/notifications.yaml | 4 +- .../{adaptive.yaml => light_adaptive.yaml} | 0 ...night.yaml => light_night_automation.yaml} | 0 .../{lightscenes.yaml => light_scenes.yaml} | 0 packages/light/light_snapshot.yaml | 20 +++ packages/light/lightstore.yaml | 81 ------------ python_scripts/light_store.py | 119 ------------------ 11 files changed, 106 insertions(+), 268 deletions(-) rename packages/light/{adaptive.yaml => light_adaptive.yaml} (100%) rename packages/light/{night.yaml => light_night_automation.yaml} (100%) rename packages/light/{lightscenes.yaml => light_scenes.yaml} (100%) create mode 100644 packages/light/light_snapshot.yaml delete mode 100644 packages/light/lightstore.yaml delete mode 100644 python_scripts/light_store.py diff --git a/packages/button/button_logic.yaml b/packages/button/button_logic.yaml index 4d3dc30..fdc266d 100644 --- a/packages/button/button_logic.yaml +++ b/packages/button/button_logic.yaml @@ -102,9 +102,13 @@ script: state: "on" then: - service: script.summary_notification - - service: light.turn_on - target: - entity_id: light.all_lights + else: + - service: scene.turn_on + target: + entity_id: scene.snapshot_all + #- service: light.turn_on + # target: + # entity_id: light.all_lights # 1,0 Ceiling - if: - condition: @@ -115,6 +119,9 @@ script: - service: light.turn_on target: entity_id: light.ceiling + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 2,0 Bed - if: - condition: @@ -125,6 +132,9 @@ script: - service: light.turn_on target: entity_id: light.bed_ceiling + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 3,0 Indirect - if: - condition: @@ -135,6 +145,9 @@ script: - service: light.turn_on target: entity_id: light.all_indirect + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 4,0 All Lights - if: - condition: @@ -145,6 +158,9 @@ script: - service: light.turn_on target: entity_id: light.all_lights + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 0,1 Adaptive - if: - condition: @@ -155,6 +171,9 @@ script: - service: scene.turn_on target: entity_id: scene.light_adaptive + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 0,2 Night - if: - condition: @@ -165,6 +184,9 @@ script: - service: scene.turn_on target: entity_id: scene.light_night + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 0,3 Bright - if: - condition: @@ -175,13 +197,9 @@ script: - service: scene.turn_on target: entity_id: scene.light_bright - - delay: - hours: 0 - minutes: 0 - seconds: 2 - milliseconds: 0 - - service: script.light_store_save - + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot mode: single #----------------------------------------------------------------------------------# # Down @@ -189,7 +207,6 @@ script: pos_down: alias: pos_down sequence: - - service: script.light_store_save # 0,0 - if: - condition: and @@ -208,9 +225,10 @@ script: state: "off" then: - service: script.summary_notification - - service: light.turn_off - target: - entity_id: light.all_lights + else: + - service: light.turn_off + target: + entity_id: light.all_lights # 1,0 Ceiling - if: - condition: @@ -221,6 +239,9 @@ script: - service: light.turn_off target: entity_id: light.ceiling + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 2,0 Bed - if: - condition: @@ -231,6 +252,9 @@ script: - service: light.turn_off target: entity_id: light.bed_ceiling + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 3,0 Indirect - if: - condition: @@ -241,6 +265,9 @@ script: - service: light.turn_off target: entity_id: light.all_indirect + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # 4,0 All Lights - if: - condition: @@ -337,12 +364,9 @@ automation: - input_number.pos_left to: "1.0" action: - - service: script.light_ceiling_save - - delay: - hours: 0 - minutes: 0 - seconds: 0 - milliseconds: 500 + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot - service: light.turn_on data: effect: Twitter @@ -353,7 +377,9 @@ automation: minutes: 0 seconds: 1 milliseconds: 0 - - service: script.light_ceiling_restore + - service: scene.turn_on + target: + entity_id: scene.snapshot_all # Pos 2,0 Ceiling Bed - alias: pos_2_0_flash mode: single @@ -363,12 +389,9 @@ automation: - input_number.pos_left to: "2.0" action: - - service: script.light_ceiling_bed_save - - delay: - hours: 0 - minutes: 0 - seconds: 0 - milliseconds: 500 + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot - service: light.turn_on data: effect: Twitter @@ -379,7 +402,9 @@ automation: minutes: 0 seconds: 1 milliseconds: 0 - - service: script.light_ceiling_bed_restore + - service: scene.turn_on + target: + entity_id: scene.snapshot_all # Pos 3,0 Indirect - alias: pos_3_0_flash mode: single @@ -389,12 +414,9 @@ automation: - input_number.pos_left to: "3.0" action: - - service: script.light_indirect_save - - delay: - hours: 0 - minutes: 0 - seconds: 0 - milliseconds: 500 + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot - service: light.turn_on data: effect: Twitter @@ -405,7 +427,9 @@ automation: minutes: 0 seconds: 1 milliseconds: 0 - - service: script.light_indirect_restore + - service: scene.turn_on + target: + entity_id: scene.snapshot_all # Pos 4,0 All Lights - alias: pos_4_0_flash mode: single @@ -415,12 +439,9 @@ automation: - input_number.pos_left to: "4.0" action: - - service: script.light_store_save - - delay: - hours: 0 - minutes: 0 - seconds: 0 - milliseconds: 500 + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot - service: light.turn_on data: effect: Twitter @@ -431,7 +452,9 @@ automation: minutes: 0 seconds: 1 milliseconds: 0 - - service: script.light_store_restore + - service: scene.turn_on + target: + entity_id: scene.snapshot_all # Pos 0,1 Adaptive - alias: pos_0_1_flash mode: single @@ -444,6 +467,9 @@ automation: - service: scene.turn_on target: entity_id: scene.light_adaptive + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # Pos 0,2 - alias: pos_0_2_flash mode: single @@ -456,6 +482,9 @@ automation: - service: scene.turn_on target: entity_id: scene.light_night + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot # Pos 0,3 - alias: pos_0_3_flash mode: single @@ -467,4 +496,7 @@ automation: action: - service: scene.turn_on target: - entity_id: scene.light_bright \ No newline at end of file + entity_id: scene.light_bright + - service: automation.trigger + target: + entity_id: automation.light_all_snapshot \ No newline at end of file diff --git a/packages/climate/weather.yaml b/packages/climate/weather.yaml index ad8841d..9d6df1c 100644 --- a/packages/climate/weather.yaml +++ b/packages/climate/weather.yaml @@ -6,32 +6,22 @@ ## -------------------------------------------------------------------------------------------------## ## Wetter-Plattform ## -------------------------------------------------------------------------------------------------## -weather: - - platform: pirateweather - api_key: !secret pirateweather - mode: daily - -sun: - - sensor: - platform: template sensors: temperature_outside: - value_template: '{{ states.weather.home.attributes.temperature }}' + value_template: '{{ states.weather.openweathermap.attributes.temperature }}' friendly_name: 'Outside Temperature' unit_of_measurement: '°C' - temperature_today_max: + temperature_today: value_template: > - {{ state_attr('weather.pirateweather', 'forecast')[0].temperature }} + {{ state_attr('weather.home', 'forecast')[0].temperature }} friendly_name: 'Max Temperature' unit_of_measurement: '°C' - temperature_today_min: - value_template: > - {{ state_attr("weather.pirateweather", "forecast")[0].templow }} - friendly_name: 'Min Temperature' - unit_of_measurement: '°C' temperature_today_condition: value_template: > - {{ state_attr('weather.pirateweather', 'forecast')[0].condition }} - friendly_name: 'Condition' \ No newline at end of file + {{ state_attr('weather.home', 'forecast')[0].condition }} + friendly_name: 'Condition' + + +sun: \ No newline at end of file diff --git a/packages/homeassistant/homeassistant.yaml b/packages/homeassistant/homeassistant.yaml index a36ac90..36b02f2 100644 --- a/packages/homeassistant/homeassistant.yaml +++ b/packages/homeassistant/homeassistant.yaml @@ -39,7 +39,6 @@ history: map: mobile_app: person: -python_script: ssdp: system_health: timer: diff --git a/packages/homeassistant/notification_summary.yaml b/packages/homeassistant/notification_summary.yaml index deff139..2ffdbd7 100644 --- a/packages/homeassistant/notification_summary.yaml +++ b/packages/homeassistant/notification_summary.yaml @@ -4,13 +4,12 @@ script: - service: notify.notify data: message: > - {% set maxTemp = states("sensor.temperature_today_max") %} - {% set minTemp = states("sensor.temperature_today_min") %} + {% set maxTemp = states("sensor.temperature_today") %} {% set condition = states("sensor.temperature_today_condition") %} {% set currentTemp = states("sensor.temperature_outside") %} {% set recommendation = states("sensor.climate_temp_recommendation") %} {% set insideTemp = states("sensor.temperature_kai_temperature") %} At the moment it is {{ condition }} outside with a temperature of {{ currentTemp }}°C. - Todays temperature will be between {{ maxTemp }}°C and {{ minTemp }}°C. + Todays max temperature will be {{ maxTemp }}°C. It is {{ insideTemp }} inside and recommended to {{ recommendation }}. mode: single \ No newline at end of file diff --git a/packages/homeassistant/notifications.yaml b/packages/homeassistant/notifications.yaml index 0e901cc..2d56b73 100644 --- a/packages/homeassistant/notifications.yaml +++ b/packages/homeassistant/notifications.yaml @@ -3,6 +3,4 @@ notify: name: browser vapid_pub_key: !secret google_api_pub vapid_prv_key: !secret google_api_priv - vapid_email: !secret google_api_email - - + vapid_email: !secret google_api_email \ No newline at end of file diff --git a/packages/light/adaptive.yaml b/packages/light/light_adaptive.yaml similarity index 100% rename from packages/light/adaptive.yaml rename to packages/light/light_adaptive.yaml diff --git a/packages/light/night.yaml b/packages/light/light_night_automation.yaml similarity index 100% rename from packages/light/night.yaml rename to packages/light/light_night_automation.yaml diff --git a/packages/light/lightscenes.yaml b/packages/light/light_scenes.yaml similarity index 100% rename from packages/light/lightscenes.yaml rename to packages/light/light_scenes.yaml diff --git a/packages/light/light_snapshot.yaml b/packages/light/light_snapshot.yaml new file mode 100644 index 0000000..46af745 --- /dev/null +++ b/packages/light/light_snapshot.yaml @@ -0,0 +1,20 @@ +automation: + - alias: light_all_snapshot + mode: single + trigger: + - platform: time_pattern + seconds: "30" + condition: + - condition: state + entity_id: light.all_lights + state: "on" + action: + - service: scene.create + data: + scene_id: snapshot_all + snapshot_entities: + - light.all_indirect + - light.bed_ceiling + - light.ceiling + - switch.adaptive_lighting_sleep_mode_default + - switch.adaptive_lighting_default \ No newline at end of file diff --git a/packages/light/lightstore.yaml b/packages/light/lightstore.yaml deleted file mode 100644 index 1cc0305..0000000 --- a/packages/light/lightstore.yaml +++ /dev/null @@ -1,81 +0,0 @@ -## -------------------------------------------------------------------------------------------------## -## Light_Store -## https://github.com/pnbruckner/homeassistant-config/blob/master/python_scripts/light_store.py -## -------------------------------------------------------------------------------------------------## -script: - #----------------------------------------------------------------------------------# - # All Lights - #----------------------------------------------------------------------------------# - light_store_save: - sequence: - - service: python_script.light_store - data: - store_name: flash_store - entity_id: - - light.bed - - light.ceiling - - light.desk - - light.bed_ceiling - - light.tv - light_store_off: - sequence: - - service: script.light_store_save - - service: light.turn_off - entity_id: light.all_lights - light_store_restore: - sequence: - - service: python_script.light_store - data: - store_name: flash_store - operation: restore - - #----------------------------------------------------------------------------------# - # Ceiling only - #----------------------------------------------------------------------------------# - light_ceiling_save: - sequence: - - service: python_script.light_store - data: - store_name: ceiling_store - entity_id: - - light.ceiling - light_ceiling_restore: - sequence: - - service: python_script.light_store - data: - store_name: ceiling_store - operation: restore - - #----------------------------------------------------------------------------------# - # Ceiling Bed only - #----------------------------------------------------------------------------------# - light_ceiling_bed_save: - sequence: - - service: python_script.light_store - data: - store_name: ceiling_store - entity_id: - - light.bed_ceiling - light_ceiling_bed_restore: - sequence: - - service: python_script.light_store - data: - store_name: ceiling_store - operation: restore - - #----------------------------------------------------------------------------------# - # Indirect only - #----------------------------------------------------------------------------------# - light_indirect_save: - sequence: - - service: python_script.light_store - data: - store_name: ceiling_store - entity_id: - - light.all_indirect - light_indirect_restore: - sequence: - - service: python_script.light_store - data: - store_name: ceiling_store - operation: restore \ No newline at end of file diff --git a/python_scripts/light_store.py b/python_scripts/light_store.py deleted file mode 100644 index 1340bb2..0000000 --- a/python_scripts/light_store.py +++ /dev/null @@ -1,119 +0,0 @@ -VERSION = '1.2.0' - -DOMAIN = 'light_store' - -ATTR_OPERATION = 'operation' -ATTR_OP_SAVE = 'save' -ATTR_OP_RESTORE = 'restore' -ATTR_OVERWRITE = 'overwrite' - -ATTR_STORE_NAME = 'store_name' -ATTR_ENTITY_ID = 'entity_id' - -# Select light attributes to save/restore. -ATTR_BRIGHTNESS = "brightness" -ATTR_EFFECT = "effect" -ATTR_WHITE_VALUE = "white_value" -ATTR_COLOR_TEMP = "color_temp" -ATTR_HS_COLOR = "hs_color" -# Save any of these attributes. -GEN_ATTRS = [ATTR_BRIGHTNESS, ATTR_EFFECT] -# Save only one of these attributes, in order of precedence. -COLOR_ATTRS = [ATTR_WHITE_VALUE, ATTR_COLOR_TEMP, ATTR_HS_COLOR] - -def store_entity_id(store_name, entity_id): - return '{}.{}'.format(store_name, entity_id.replace('.', '_')) - -# Get operation (default to save.) -operation = data.get(ATTR_OPERATION, ATTR_OP_SAVE) -if operation not in [ATTR_OP_SAVE, ATTR_OP_RESTORE]: - logger.error('Invalid operation. Expected {} or {}, got: {}'.format( - ATTR_OP_SAVE, ATTR_OP_RESTORE, operation)) -else: - # Get optional store name (default to DOMAIN.) - store_name = data.get(ATTR_STORE_NAME, DOMAIN) - - # Get optional overwrite parameter (only applies to saving.) - overwrite = data.get(ATTR_OVERWRITE, True) - - # Get optional list (or comma separated string) of switches & lights to - # save/restore. - entity_id = data.get(ATTR_ENTITY_ID) - if isinstance(entity_id, str): - entity_id = [e.strip() for e in entity_id.split(',')] - - # Replace any group entities with their contents. - # Repeat until no groups left in list. - expanded_a_group = True - while entity_id and expanded_a_group: - expanded_a_group = False - for e in entity_id: - if e.startswith('group.'): - entity_id.remove(e) - g = hass.states.get(e) - if g and 'entity_id' in g.attributes: - entity_id.extend(g.attributes['entity_id']) - expanded_a_group = True - - # Get lists of switches and lights that actually exist, - # and list of entities that were previously saved. - entity_ids = (hass.states.entity_ids('switch') + - hass.states.entity_ids('light')) - saved = hass.states.entity_ids(store_name) - # When restoring, limit to existing entities that were saved. - if operation == ATTR_OP_RESTORE: - saved_entity_ids = [] - for e in entity_ids: - if store_entity_id(store_name, e) in saved: - saved_entity_ids.append(e) - entity_ids = saved_entity_ids - - # If a list of entities was specified, further limit to just those. - # Otherwise, save all existing switches and lights, or restore - # all existing switches and lights that were previously saved. - if entity_id: - entity_ids = tuple(set(entity_ids).intersection(set(entity_id))) - - if operation == ATTR_OP_SAVE: - # Only save if not already saved, or if overwite is True. - if not saved or overwrite: - # Clear out any previously saved states. - for entity_id in saved: - hass.states.remove(entity_id) - - # Save selected switches and lights to store. - for entity_id in entity_ids: - cur_state = hass.states.get(entity_id) - if cur_state is None: - logger.error('Could not get state of {}.'.format(entity_id)) - else: - attributes = {} - if entity_id.startswith('light.') and cur_state.state == 'on': - for attr in GEN_ATTRS: - if attr in cur_state.attributes: - attributes[attr] = cur_state.attributes[attr] - for attr in COLOR_ATTRS: - if attr in cur_state.attributes: - attributes[attr] = cur_state.attributes[attr] - break - hass.states.set(store_entity_id(store_name, entity_id), - cur_state.state, attributes) - else: - # Restore selected switches and lights from store. - for entity_id in entity_ids: - old_state = hass.states.get(store_entity_id(store_name, entity_id)) - if old_state is None: - logger.error('No saved state for {}.'.format(entity_id)) - else: - turn_on = old_state.state == 'on' - service_data = {'entity_id': entity_id} - component = entity_id.split('.')[0] - if component == 'light' and turn_on and old_state.attributes: - service_data.update(old_state.attributes) - hass.services.call(component, - 'turn_on' if turn_on else 'turn_off', - service_data) - - # Remove saved states now that we're done with them. - for entity_id in saved: - hass.states.remove(entity_id) \ No newline at end of file