367 lines
14 KiB
YAML
367 lines
14 KiB
YAML
- alias: Ambient Light | Set Quantize Values
|
||
description: 'This automation ''quantizes'' the raw lux values reported by the ambient
|
||
sensor devices into text values of Bright, Dim, Dark, or Night. These quantized
|
||
values are what I use to trigger ambient light related automations. <br> **04/25/2025**: Created
|
||
this automation to update both of the ''real'' sensors.'
|
||
triggers:
|
||
- trigger: time_pattern
|
||
minutes: /5
|
||
conditions: []
|
||
actions:
|
||
- repeat:
|
||
for_each:
|
||
- sensor: sensor.ambient_light_sensor_s2_bh1750_lux
|
||
quantized: input_text.ambient_s2_quantized
|
||
night_lux: input_number.ambient_s2_quant_night_lux
|
||
dark_lux: input_number.ambient_s2_quant_dark_lux
|
||
dim_lux: input_number.ambient_s2_quant_dim_lux
|
||
- sensor: sensor.adafruit_feather_sensors_bh1750_illuminance
|
||
quantized: input_text.ambient_s1_quantized
|
||
night_lux: input_number.ambient_s1_quant_night_lux
|
||
dark_lux: input_number.ambient_s1_quant_dark_lux
|
||
dim_lux: input_number.ambient_s1_quant_dim_lux
|
||
sequence:
|
||
- choose:
|
||
- conditions:
|
||
- condition: template
|
||
value_template: '{% set lux = states(repeat.item.sensor) | float %} {%
|
||
set n = states(repeat.item.night_lux) | float %} {% set d = states(repeat.item.dark_lux) |
|
||
float %} {{ lux > n and lux < d }}
|
||
|
||
'
|
||
sequence:
|
||
- target:
|
||
entity_id: '{{ repeat.item.quantized }}'
|
||
data:
|
||
value: Dark
|
||
action: input_text.set_value
|
||
- conditions:
|
||
- condition: template
|
||
value_template: '{% set lux = states(repeat.item.sensor) | float %} {%
|
||
set d = states(repeat.item.dark_lux) | float %} {% set di = states(repeat.item.dim_lux) |
|
||
float %} {{ lux > d and lux < di }}
|
||
|
||
'
|
||
sequence:
|
||
- target:
|
||
entity_id: '{{ repeat.item.quantized }}'
|
||
data:
|
||
value: Dim
|
||
action: input_text.set_value
|
||
- conditions:
|
||
- condition: template
|
||
value_template: '{% set lux = states(repeat.item.sensor) | float %} {%
|
||
set di = states(repeat.item.dim_lux) | float %} {{ lux > di }}
|
||
|
||
'
|
||
sequence:
|
||
- target:
|
||
entity_id: '{{ repeat.item.quantized }}'
|
||
data:
|
||
value: Bright
|
||
action: input_text.set_value
|
||
default:
|
||
- target:
|
||
entity_id: '{{ repeat.item.quantized }}'
|
||
data:
|
||
value: Night
|
||
action: input_text.set_value
|
||
mode: single
|
||
- alias: Ambient Sensors | State Changed
|
||
description: 'This is part of my handling of changes to ambient light and the day-dim
|
||
application. This automation catches an ambient light level change for any of
|
||
the lux sensors and to then calls the ''lightset_assess_conditions'' script. <br>
|
||
**04/25/2025**: Implemented and is working.'
|
||
triggers:
|
||
- trigger: state
|
||
entity_id:
|
||
- input_text.ambient_s9_quantized
|
||
- input_text.ambient_s1_quantized
|
||
- input_text.ambient_s2_quantized
|
||
from: null
|
||
to: null
|
||
conditions: []
|
||
actions:
|
||
- variables:
|
||
trigger_map:
|
||
input_text.ambient_s9_quantized: input_text.ambient_s9_lightset_label
|
||
input_text.ambient_s1_quantized: input_text.ambient_s1_lightset_label
|
||
input_text.ambient_s2_quantized: input_text.ambient_s2_lightset_label
|
||
sensor_label_helper: '{{ trigger_map[trigger.entity_id] }}'
|
||
lightset_label: '{{ states(sensor_label_helper) | default(''NoLightsetLabel'')
|
||
}}'
|
||
alias: Define Needed Variables
|
||
- alias: Debug - Show Variables
|
||
data:
|
||
name: Lightset Debug
|
||
message: 'VARIABLE: [sensor_label_helper: {{ sensor_label_helper }}] || VARIABLE:
|
||
[lightset_label: {{lightset_label }}]
|
||
|
||
'
|
||
action: logbook.log
|
||
- action: script.turn_on
|
||
metadata: {}
|
||
data:
|
||
entity_id: script.lightset_assess_conditions
|
||
variables:
|
||
lightset_label: '{{ lightset_label }}'
|
||
mode: parallel
|
||
- alias: Light Set - Lset App Test Light Set | Deactivate Requested
|
||
description: ''
|
||
triggers:
|
||
- trigger: state
|
||
entity_id:
|
||
- input_button.light_set_lset_app_test_light_set_deactivate
|
||
- input_button.light_set_lset_app_test_light_set_disable
|
||
from: null
|
||
to: null
|
||
conditions: []
|
||
actions:
|
||
- variables:
|
||
button_map:
|
||
input_button.light_set_lset_app_test_light_set_deactivate:
|
||
target_lightset_label: Light Set - Lset App Test Light Set
|
||
target_exit_state: Deactivated
|
||
input_button.light_set_lset_app_test_light_set_disable:
|
||
target_lightset_label: Light Set - Lset App Test Light Set
|
||
target_exit_state: Disabled
|
||
target_lightset_label: '{{ button_map[trigger.entity_id].target_lightset_label
|
||
}}'
|
||
target_exit_state: '{{ button_map[trigger.entity_id].target_exit_state }}'
|
||
- action: script.turn_on
|
||
metadata: {}
|
||
data:
|
||
variables:
|
||
lightset_label: '{{ target_lightset_label }}'
|
||
exit_state: '{{ target_exit_state }}'
|
||
target:
|
||
entity_id:
|
||
- script.lightset_deactivate_disable
|
||
mode: parallel
|
||
- alias: lightset | State Changed
|
||
description: '**Membership**: *Lightset Virtual Object* and an element of the Day-Dim
|
||
App. <br> **Purpose**: React to light-set state changes and route actions to the
|
||
appropriate action scripts that are part of the app. <br> **Note-1**: I am using
|
||
the non-blocking form of calling the routed to scripts in the ''''choose'''' section
|
||
so that this automation can be called again immediately (i.e., by a different
|
||
light-set having been triggered). <br> **Note-2**: *mode: queued* is important
|
||
as the call out to the LED set indicator script is recursive and will fail if
|
||
mode is single. (Actually it should likely be mode: parallel if ever I use the
|
||
feature to set a ''''start_state'''' in the scripts that turn the lights on and
|
||
off). <br> **04/26/2025**: Fixed error in lightset strings in the trigger_map
|
||
table. <br> **04/25/2025**: Fixed up for new naming of helpers. <br> **04/22/2025**:
|
||
Added case for ''''Inactive'''' to set *<lightset> | Operational State* to ''''Activate''''
|
||
<br> **Documentation** .../HomeAssistant/Documentation/doc_diagrams.odg
|
||
|
||
'
|
||
triggers:
|
||
- trigger: state
|
||
entity_id:
|
||
- input_select.lightset_test_set_state
|
||
- input_select.lightset_kitchen_state
|
||
- input_select.lightset_living_area_state
|
||
conditions: []
|
||
actions:
|
||
- variables:
|
||
trigger_map:
|
||
input_select.lightset_test_set_state:
|
||
lightset: Light-Set - Day-Dim | Test Set
|
||
operational_state_helper: input_select.lightset_test_set_operational_state
|
||
input_select.lightset_kitchen_state:
|
||
lightset: Light-Set - Day-Dim | Kitchen
|
||
operational_state_helper: input_select.lightset_kitchen_operational_state
|
||
input_select.lightset_living_area_state:
|
||
lightset: Light-Set - Day-Dim | Living Area
|
||
operational_state_helper: input_select.lightset_living_area_operational_state
|
||
lightset: '{{ trigger_map[trigger.entity_id].lightset }}'
|
||
ops_state_helper: '{{ trigger_map[trigger.entity_id].operational_state_helper
|
||
}}'
|
||
alias: Define Needed Variables
|
||
- alias: Debug - Show Variables
|
||
data:
|
||
name: Lightset Debug
|
||
message: 'VARIABLE: [lightset: {{ lightset }}] || VARIABLE: [ops_state_helper:
|
||
{{ ops_state_helper }}] || VALUE: [trigger.entity_id: {{ trigger.entity_id
|
||
}}] || VALUE: [trigger.to_state.state: {{ trigger.to_state.state }}] ||
|
||
|
||
'
|
||
action: logbook.log
|
||
- action: script.lightset_set_state_indicators
|
||
metadata: {}
|
||
data:
|
||
changed_helper: '{{ trigger.entity_id }}'
|
||
new_state: '{{ trigger.to_state.state }}'
|
||
alias: CALL Script to Set ESPHome LED Indicators for New State
|
||
- alias: CASE Section | Route to Appropriate Handler Based on New State
|
||
choose:
|
||
- alias: CASE-0 State Changed to 'In Process - ON'
|
||
conditions:
|
||
- condition: template
|
||
alias: IF State is In Process - On
|
||
value_template: '{{ trigger.to_state.state == ''In Process - ON''}}'
|
||
sequence:
|
||
- alias: Turn on the Light Set
|
||
action: script.turn_on
|
||
data:
|
||
entity_id: script.lightset_on_by_label
|
||
variables:
|
||
lightset_label: '{{ lightset }}'
|
||
- alias: CASE-1 State Changed to 'Pending - OFF'
|
||
conditions:
|
||
- condition: template
|
||
alias: IF State is Pending - OFF
|
||
value_template: '{{ trigger.to_state.state == ''Pending - OFF''}}'
|
||
sequence:
|
||
- alias: Turn on Delay Timer for Light Set
|
||
action: script.turn_on
|
||
data:
|
||
entity_id: script.lightset_goto_pending_off
|
||
variables:
|
||
lightset_label: '{{ lightset }}'
|
||
- alias: CASE-2 State Changed to 'In Process - OFF'
|
||
conditions:
|
||
- condition: template
|
||
alias: IF State is In Process - OFF
|
||
value_template: '{{ trigger.to_state.state == ''In Process - OFF''}}'
|
||
sequence:
|
||
- alias: Turn off the Light Set
|
||
action: script.turn_on
|
||
data:
|
||
entity_id: script.lightset_off_by_areas
|
||
variables:
|
||
lightset_label: '{{ lightset }}'
|
||
- alias: CASE-3 State Changed to Cancel In Process
|
||
conditions:
|
||
- condition: template
|
||
alias: IF State is Cancel In Process
|
||
value_template: '{{ trigger.to_state.state == ''Cancel In Process''}}'
|
||
sequence:
|
||
- alias: Cancel any active light-set activity
|
||
action: script.turn_on
|
||
data:
|
||
entity_id: script.lightset_cancel
|
||
variables:
|
||
lightset_label: '{{ lightset }}'
|
||
- alias: CASE-4 State Changed to 'Inactive' from 'Cancel In Process'
|
||
conditions:
|
||
- condition: template
|
||
alias: IF State went to 'Inactive' from 'Cancel In Process'
|
||
value_template: '{{ trigger.to_state.state == ''Inactive'' and trigger.from_state.state
|
||
== ''Cancel In Process''}}'
|
||
sequence:
|
||
- alias: Set Light-Set's Operational State to 'Activate.'
|
||
action: input_select.select_option
|
||
metadata: {}
|
||
data:
|
||
option: Activate
|
||
target:
|
||
entity_id: '{{ ops_state_helper }}'
|
||
mode: queued
|
||
- alias: lightset | Transition Timer Expired
|
||
description: '**Purpose**: Detect when a light-set''s transition delay timer has
|
||
expired and take appropriate action. <br> **04/26/2025**: Fixed helper name errors.
|
||
Added test for valid timer in loopup map. <br> **04/25/2025**: Fixed up for new
|
||
naming of helpers and added in the two non-test light-sets. <br> **04/12/2025**:
|
||
Initial Creation
|
||
|
||
'
|
||
triggers:
|
||
- trigger: state
|
||
entity_id:
|
||
- timer.lightset_test_set_timer
|
||
- timer.lightset_kitchen_timer
|
||
- timer.lightset_living_area_timer
|
||
from: null
|
||
to: idle
|
||
alias: When any Light-Set's timer has finished
|
||
conditions: []
|
||
actions:
|
||
- variables:
|
||
trigger_map:
|
||
timer.lightset_test_set_timer:
|
||
label: Light-Set - Day-Dim | Test Set
|
||
state_helper: input_select.lightset_test_set_state
|
||
timer.lightset_kitchen_timer:
|
||
label: Light-Set - Day-Dim | Kitchen
|
||
state_helper: input_select.lightset_test_set_state
|
||
timer.lightset_living_area_timer:
|
||
label: Light-Set - Day-Dim | Living Area
|
||
state_helper: input_select.lightset_test_set_state
|
||
NoMappedTimer:
|
||
label: NoLightsetLabel
|
||
state_helper: NoStateHelper
|
||
timer_to_act_on: "{% if trigger.entity_id in trigger_map %}\n {{ trigger.entity_id\
|
||
\ }}\n{% else %}\n NoMappedTimer\n{% endif %}\n"
|
||
target_lightset_label: '{{ trigger_map[timer_to_act_on].label }}'
|
||
target_state_helper: '{{ trigger_map[timer_to_act_on].state_helper }}'
|
||
- alias: Debug - Show Variables
|
||
data:
|
||
name: Lightset Debug
|
||
message: 'VARIABLE: [timer_to_act_on: {{ timer_to_act_on }}] || VARIABLE: [target_lightset_label:
|
||
{{ target_lightset_label }}] || VARIABLE: [target_state_helper: {{ target_state_helper
|
||
}}] || VALUE: [trigger.entity_id: {{ trigger.entity_id }} ] || VALUE: [trigger.to_state.state:
|
||
{{ trigger.to_state.state }} ] ||
|
||
|
||
'
|
||
action: logbook.log
|
||
- alias: If we have valid timer call assess conditions script, else error
|
||
choose:
|
||
- alias: Call the Light-Set Assess Conditions Script.
|
||
conditions:
|
||
- condition: template
|
||
value_template: '{{ timer_to_act_on != ''NoMappedTimer'' }}'
|
||
sequence:
|
||
- action: script.turn_on
|
||
metadata: {}
|
||
data:
|
||
variables:
|
||
lightset_label: '{{ target_lightset_label }}'
|
||
target:
|
||
entity_id:
|
||
- script.lightset_assess_conditions
|
||
default:
|
||
- alias: No timer, report error
|
||
sequence:
|
||
- data:
|
||
name: Automation | lightset Transition Timer Expired - ERROR
|
||
message: Triggering timer - '{{ trigger.entity_id }}' - has no entry in
|
||
trigger_map lookup table.
|
||
action: logbook.log
|
||
mode: parallel
|
||
- alias: Away Random Lights by Label
|
||
description: 'When I''m away, randomly toggle any light tagged “Light Set – Night
|
||
Random” between night and bedtime.
|
||
|
||
'
|
||
trigger:
|
||
- platform: time_pattern
|
||
minutes: /5
|
||
variables:
|
||
lights: "{{ states.light\n | selectattr('attributes.label','eq','Light Set -\
|
||
\ Night Random')\n | map(attribute='entity_id')\n | list }}"
|
||
condition:
|
||
- condition: state
|
||
entity_id: input_boolean.away_from_home
|
||
state: 'on'
|
||
- condition: template
|
||
value_template: '{{ is_state(''sensor.daypart'',''nighttime'') }}
|
||
|
||
'
|
||
- condition: template
|
||
value_template: '{{ now().strftime(''%H:%M'') < states(''input_datetime.bedtime_normal'')
|
||
}}
|
||
|
||
'
|
||
- condition: template
|
||
value_template: '{{ (range(0,5) | random) == 0 }}
|
||
|
||
'
|
||
action:
|
||
- choose:
|
||
- conditions: '{{ lights | length > 0 }}'
|
||
sequence:
|
||
- service: light.toggle
|
||
target:
|
||
entity_id: '{{ lights | random }}'
|
||
mode: parallel
|