Updates
This commit is contained in:
parent
cc620be332
commit
4390be9d72
@ -102,9 +102,13 @@ script:
|
|||||||
state: "on"
|
state: "on"
|
||||||
then:
|
then:
|
||||||
- service: script.summary_notification
|
- service: script.summary_notification
|
||||||
- service: light.turn_on
|
else:
|
||||||
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: light.all_lights
|
entity_id: scene.snapshot_all
|
||||||
|
#- service: light.turn_on
|
||||||
|
# target:
|
||||||
|
# entity_id: light.all_lights
|
||||||
# 1,0 Ceiling
|
# 1,0 Ceiling
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -115,6 +119,9 @@ script:
|
|||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: light.ceiling
|
entity_id: light.ceiling
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 2,0 Bed
|
# 2,0 Bed
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -125,6 +132,9 @@ script:
|
|||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: light.bed_ceiling
|
entity_id: light.bed_ceiling
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 3,0 Indirect
|
# 3,0 Indirect
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -135,6 +145,9 @@ script:
|
|||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: light.all_indirect
|
entity_id: light.all_indirect
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 4,0 All Lights
|
# 4,0 All Lights
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -145,6 +158,9 @@ script:
|
|||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: light.all_lights
|
entity_id: light.all_lights
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 0,1 Adaptive
|
# 0,1 Adaptive
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -155,6 +171,9 @@ script:
|
|||||||
- service: scene.turn_on
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: scene.light_adaptive
|
entity_id: scene.light_adaptive
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 0,2 Night
|
# 0,2 Night
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -165,6 +184,9 @@ script:
|
|||||||
- service: scene.turn_on
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: scene.light_night
|
entity_id: scene.light_night
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 0,3 Bright
|
# 0,3 Bright
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -175,13 +197,9 @@ script:
|
|||||||
- service: scene.turn_on
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: scene.light_bright
|
entity_id: scene.light_bright
|
||||||
- delay:
|
- service: automation.trigger
|
||||||
hours: 0
|
target:
|
||||||
minutes: 0
|
entity_id: automation.light_all_snapshot
|
||||||
seconds: 2
|
|
||||||
milliseconds: 0
|
|
||||||
- service: script.light_store_save
|
|
||||||
|
|
||||||
mode: single
|
mode: single
|
||||||
#----------------------------------------------------------------------------------#
|
#----------------------------------------------------------------------------------#
|
||||||
# Down
|
# Down
|
||||||
@ -189,7 +207,6 @@ script:
|
|||||||
pos_down:
|
pos_down:
|
||||||
alias: pos_down
|
alias: pos_down
|
||||||
sequence:
|
sequence:
|
||||||
- service: script.light_store_save
|
|
||||||
# 0,0
|
# 0,0
|
||||||
- if:
|
- if:
|
||||||
- condition: and
|
- condition: and
|
||||||
@ -208,6 +225,7 @@ script:
|
|||||||
state: "off"
|
state: "off"
|
||||||
then:
|
then:
|
||||||
- service: script.summary_notification
|
- service: script.summary_notification
|
||||||
|
else:
|
||||||
- service: light.turn_off
|
- service: light.turn_off
|
||||||
target:
|
target:
|
||||||
entity_id: light.all_lights
|
entity_id: light.all_lights
|
||||||
@ -221,6 +239,9 @@ script:
|
|||||||
- service: light.turn_off
|
- service: light.turn_off
|
||||||
target:
|
target:
|
||||||
entity_id: light.ceiling
|
entity_id: light.ceiling
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 2,0 Bed
|
# 2,0 Bed
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -231,6 +252,9 @@ script:
|
|||||||
- service: light.turn_off
|
- service: light.turn_off
|
||||||
target:
|
target:
|
||||||
entity_id: light.bed_ceiling
|
entity_id: light.bed_ceiling
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 3,0 Indirect
|
# 3,0 Indirect
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -241,6 +265,9 @@ script:
|
|||||||
- service: light.turn_off
|
- service: light.turn_off
|
||||||
target:
|
target:
|
||||||
entity_id: light.all_indirect
|
entity_id: light.all_indirect
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# 4,0 All Lights
|
# 4,0 All Lights
|
||||||
- if:
|
- if:
|
||||||
- condition:
|
- condition:
|
||||||
@ -337,12 +364,9 @@ automation:
|
|||||||
- input_number.pos_left
|
- input_number.pos_left
|
||||||
to: "1.0"
|
to: "1.0"
|
||||||
action:
|
action:
|
||||||
- service: script.light_ceiling_save
|
- service: automation.trigger
|
||||||
- delay:
|
target:
|
||||||
hours: 0
|
entity_id: automation.light_all_snapshot
|
||||||
minutes: 0
|
|
||||||
seconds: 0
|
|
||||||
milliseconds: 500
|
|
||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
data:
|
data:
|
||||||
effect: Twitter
|
effect: Twitter
|
||||||
@ -353,7 +377,9 @@ automation:
|
|||||||
minutes: 0
|
minutes: 0
|
||||||
seconds: 1
|
seconds: 1
|
||||||
milliseconds: 0
|
milliseconds: 0
|
||||||
- service: script.light_ceiling_restore
|
- service: scene.turn_on
|
||||||
|
target:
|
||||||
|
entity_id: scene.snapshot_all
|
||||||
# Pos 2,0 Ceiling Bed
|
# Pos 2,0 Ceiling Bed
|
||||||
- alias: pos_2_0_flash
|
- alias: pos_2_0_flash
|
||||||
mode: single
|
mode: single
|
||||||
@ -363,12 +389,9 @@ automation:
|
|||||||
- input_number.pos_left
|
- input_number.pos_left
|
||||||
to: "2.0"
|
to: "2.0"
|
||||||
action:
|
action:
|
||||||
- service: script.light_ceiling_bed_save
|
- service: automation.trigger
|
||||||
- delay:
|
target:
|
||||||
hours: 0
|
entity_id: automation.light_all_snapshot
|
||||||
minutes: 0
|
|
||||||
seconds: 0
|
|
||||||
milliseconds: 500
|
|
||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
data:
|
data:
|
||||||
effect: Twitter
|
effect: Twitter
|
||||||
@ -379,7 +402,9 @@ automation:
|
|||||||
minutes: 0
|
minutes: 0
|
||||||
seconds: 1
|
seconds: 1
|
||||||
milliseconds: 0
|
milliseconds: 0
|
||||||
- service: script.light_ceiling_bed_restore
|
- service: scene.turn_on
|
||||||
|
target:
|
||||||
|
entity_id: scene.snapshot_all
|
||||||
# Pos 3,0 Indirect
|
# Pos 3,0 Indirect
|
||||||
- alias: pos_3_0_flash
|
- alias: pos_3_0_flash
|
||||||
mode: single
|
mode: single
|
||||||
@ -389,12 +414,9 @@ automation:
|
|||||||
- input_number.pos_left
|
- input_number.pos_left
|
||||||
to: "3.0"
|
to: "3.0"
|
||||||
action:
|
action:
|
||||||
- service: script.light_indirect_save
|
- service: automation.trigger
|
||||||
- delay:
|
target:
|
||||||
hours: 0
|
entity_id: automation.light_all_snapshot
|
||||||
minutes: 0
|
|
||||||
seconds: 0
|
|
||||||
milliseconds: 500
|
|
||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
data:
|
data:
|
||||||
effect: Twitter
|
effect: Twitter
|
||||||
@ -405,7 +427,9 @@ automation:
|
|||||||
minutes: 0
|
minutes: 0
|
||||||
seconds: 1
|
seconds: 1
|
||||||
milliseconds: 0
|
milliseconds: 0
|
||||||
- service: script.light_indirect_restore
|
- service: scene.turn_on
|
||||||
|
target:
|
||||||
|
entity_id: scene.snapshot_all
|
||||||
# Pos 4,0 All Lights
|
# Pos 4,0 All Lights
|
||||||
- alias: pos_4_0_flash
|
- alias: pos_4_0_flash
|
||||||
mode: single
|
mode: single
|
||||||
@ -415,12 +439,9 @@ automation:
|
|||||||
- input_number.pos_left
|
- input_number.pos_left
|
||||||
to: "4.0"
|
to: "4.0"
|
||||||
action:
|
action:
|
||||||
- service: script.light_store_save
|
- service: automation.trigger
|
||||||
- delay:
|
target:
|
||||||
hours: 0
|
entity_id: automation.light_all_snapshot
|
||||||
minutes: 0
|
|
||||||
seconds: 0
|
|
||||||
milliseconds: 500
|
|
||||||
- service: light.turn_on
|
- service: light.turn_on
|
||||||
data:
|
data:
|
||||||
effect: Twitter
|
effect: Twitter
|
||||||
@ -431,7 +452,9 @@ automation:
|
|||||||
minutes: 0
|
minutes: 0
|
||||||
seconds: 1
|
seconds: 1
|
||||||
milliseconds: 0
|
milliseconds: 0
|
||||||
- service: script.light_store_restore
|
- service: scene.turn_on
|
||||||
|
target:
|
||||||
|
entity_id: scene.snapshot_all
|
||||||
# Pos 0,1 Adaptive
|
# Pos 0,1 Adaptive
|
||||||
- alias: pos_0_1_flash
|
- alias: pos_0_1_flash
|
||||||
mode: single
|
mode: single
|
||||||
@ -444,6 +467,9 @@ automation:
|
|||||||
- service: scene.turn_on
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: scene.light_adaptive
|
entity_id: scene.light_adaptive
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# Pos 0,2
|
# Pos 0,2
|
||||||
- alias: pos_0_2_flash
|
- alias: pos_0_2_flash
|
||||||
mode: single
|
mode: single
|
||||||
@ -456,6 +482,9 @@ automation:
|
|||||||
- service: scene.turn_on
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: scene.light_night
|
entity_id: scene.light_night
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
||||||
# Pos 0,3
|
# Pos 0,3
|
||||||
- alias: pos_0_3_flash
|
- alias: pos_0_3_flash
|
||||||
mode: single
|
mode: single
|
||||||
@ -468,3 +497,6 @@ automation:
|
|||||||
- service: scene.turn_on
|
- service: scene.turn_on
|
||||||
target:
|
target:
|
||||||
entity_id: scene.light_bright
|
entity_id: scene.light_bright
|
||||||
|
- service: automation.trigger
|
||||||
|
target:
|
||||||
|
entity_id: automation.light_all_snapshot
|
@ -6,32 +6,22 @@
|
|||||||
## -------------------------------------------------------------------------------------------------##
|
## -------------------------------------------------------------------------------------------------##
|
||||||
## Wetter-Plattform
|
## Wetter-Plattform
|
||||||
## -------------------------------------------------------------------------------------------------##
|
## -------------------------------------------------------------------------------------------------##
|
||||||
weather:
|
|
||||||
- platform: pirateweather
|
|
||||||
api_key: !secret pirateweather
|
|
||||||
mode: daily
|
|
||||||
|
|
||||||
sun:
|
|
||||||
|
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
- platform: template
|
- platform: template
|
||||||
sensors:
|
sensors:
|
||||||
temperature_outside:
|
temperature_outside:
|
||||||
value_template: '{{ states.weather.home.attributes.temperature }}'
|
value_template: '{{ states.weather.openweathermap.attributes.temperature }}'
|
||||||
friendly_name: 'Outside Temperature'
|
friendly_name: 'Outside Temperature'
|
||||||
unit_of_measurement: '°C'
|
unit_of_measurement: '°C'
|
||||||
temperature_today_max:
|
temperature_today:
|
||||||
value_template: >
|
value_template: >
|
||||||
{{ state_attr('weather.pirateweather', 'forecast')[0].temperature }}
|
{{ state_attr('weather.home', 'forecast')[0].temperature }}
|
||||||
friendly_name: 'Max Temperature'
|
friendly_name: 'Max Temperature'
|
||||||
unit_of_measurement: '°C'
|
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:
|
temperature_today_condition:
|
||||||
value_template: >
|
value_template: >
|
||||||
{{ state_attr('weather.pirateweather', 'forecast')[0].condition }}
|
{{ state_attr('weather.home', 'forecast')[0].condition }}
|
||||||
friendly_name: 'Condition'
|
friendly_name: 'Condition'
|
||||||
|
|
||||||
|
|
||||||
|
sun:
|
@ -39,7 +39,6 @@ history:
|
|||||||
map:
|
map:
|
||||||
mobile_app:
|
mobile_app:
|
||||||
person:
|
person:
|
||||||
python_script:
|
|
||||||
ssdp:
|
ssdp:
|
||||||
system_health:
|
system_health:
|
||||||
timer:
|
timer:
|
||||||
|
@ -4,13 +4,12 @@ script:
|
|||||||
- service: notify.notify
|
- service: notify.notify
|
||||||
data:
|
data:
|
||||||
message: >
|
message: >
|
||||||
{% set maxTemp = states("sensor.temperature_today_max") %}
|
{% set maxTemp = states("sensor.temperature_today") %}
|
||||||
{% set minTemp = states("sensor.temperature_today_min") %}
|
|
||||||
{% set condition = states("sensor.temperature_today_condition") %}
|
{% set condition = states("sensor.temperature_today_condition") %}
|
||||||
{% set currentTemp = states("sensor.temperature_outside") %}
|
{% set currentTemp = states("sensor.temperature_outside") %}
|
||||||
{% set recommendation = states("sensor.climate_temp_recommendation") %}
|
{% set recommendation = states("sensor.climate_temp_recommendation") %}
|
||||||
{% set insideTemp = states("sensor.temperature_kai_temperature") %}
|
{% set insideTemp = states("sensor.temperature_kai_temperature") %}
|
||||||
At the moment it is {{ condition }} outside with a temperature of {{ currentTemp }}°C.
|
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 }}.
|
It is {{ insideTemp }} inside and recommended to {{ recommendation }}.
|
||||||
mode: single
|
mode: single
|
@ -4,5 +4,3 @@ notify:
|
|||||||
vapid_pub_key: !secret google_api_pub
|
vapid_pub_key: !secret google_api_pub
|
||||||
vapid_prv_key: !secret google_api_priv
|
vapid_prv_key: !secret google_api_priv
|
||||||
vapid_email: !secret google_api_email
|
vapid_email: !secret google_api_email
|
||||||
|
|
||||||
|
|
||||||
|
20
packages/light/light_snapshot.yaml
Normal file
20
packages/light/light_snapshot.yaml
Normal file
@ -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
|
@ -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
|
|
@ -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)
|
|
Reference in New Issue
Block a user