Hi Gang!
I have an automation that sets some lights based on the light level. I’d recently changed the way this works and put in some messages to help me check it which then highlighted to me when triggered, its running twice….but I can’t work out why!
The automation (<< with some comments to aid understanding)
alias: Day - Lounge
description: ''
trigger:
- platform: state
entity_id: binary_sensor.day_time << a time range when to run, used as a trigger for when these hours start
to: 'on'
- platform: state
entity_id: sensor.lounge_light_sensor << explained below
for: '00:05'
- platform: state
entity_id: group.home_occupied << is anyone in the house
condition:
- condition: state
entity_id: input_boolean.occupied << a holiday away type flag
state: 'on'
- condition: state
entity_id: binary_sensor.day_time << only run during specific hours
state: 'on'
action:
- choose:
- conditions: << are we home and is the light level low?
- condition: state
entity_id: group.home_occupied
state: home
- condition: state
entity_id: sensor.lounge_light_sensor
state: Low
sequence:
- service: notify.mike
data:
message: low light test
- scene: scene.lounge_bright
- conditions: << are we home and is the light level medium?
- condition: state
entity_id: group.home_occupied
state: home
- condition: state
entity_id: sensor.lounge_light_sensor
state: Medium
sequence:
- service: notify.mike
data:
message: medium light test
- scene: scene.lounge_half_bright
default: << all other conditions, i.e. home and high or out of the house
- service: notify.mike
data:
message: default light test turn all off
- type: turn_off
device_id: f7956afaf7894ee68e8df772e43fa6a9
entity_id: light.loungedz
domain: light
mode: restart
The primary trigger here is sensor.lounge_light_sensor
which is set as follows:
lounge_light_sensor:
friendly_name: "Lounge Light Sensor Level"
value_template: >
{% if states('sensor.lounge_light_level') | int <= states('input_number.lounge_low_light_level') | int %}
Low
{% elif states('sensor.lounge_light_level') | int > states('input_number.lounge_low_light_level') | int and states('sensor.lounge_light_level') | int < states('input_number.lounge_high_light_level') | int %}
Medium
{% elif states('sensor.lounge_light_level') | int >= states('input_number.lounge_high_light_level') | int %}
High
{% else %}
Unknown
{% endif %}
Basically, based on a low and high threshold points (input_number.lounge_[low/high]_light_level
) compared to a light reading sets itself to Low (dark), Medium (no so dark) or High (bright).
Because I’d put in little messages (as part of tuning the levels) I can see whenever it runs, it does so twice:
The first run looking through the trace we can see an appropriate trigger happening sensor.lounge_light_sensor moving from Medium to High but it fails to complete on the default action
Now I wonder if this is because my automation is set to Restart and the second run is kicking off at this stage (but in all examples stops at this level regardless of the choice it made above).
So the second run of the automation executed at what appears to be the same time looks like this: Here we can see it completes but the trigger data, From and To are the same values.
Now, things are working so not terribly important, but I’d love to understand why this is happening. I would suspect as usual it is of my own doing, but I can’t explain it. Any suggestions would be gratefully received!!