Hi,
System: HassOS 2.12
Deployment: production
Home Assistant 0.101.2
Problem with automatically switching off a group of switches
TL;DR; Only the first switch in a group is switched off.
This problem only occours when trying to switch off a group of switches using the
service: homeassistant.turn_off
method. I have a group group.garage_lights
which is defined as:
garage_lights:
icon: mdi:lightbulb
name: Garage
entities:
- switch.sonoff_1000000000_1
- switch.sonoff_1000000000_2
- switch.sonoff_1000000000_3
There is an automation to turn on these lights when my wife comes home:
- id: garage-lights-on-when-gail-comes-home
alias: "Garage lights on when Jane comes home"
initial_state: true
trigger:
platform: state
entity_id: person.jane_doe
to: 'home'
condition:
condition: state
entity_id: group.garage_lights
state: 'off'
action:
- service: timer.start
entity_id: timer.garage_lights_on_switch_bounce
- service: homeassistant.turn_on
entity_id: group.garage_lights
The switch bounce timer was implemented because I noticed at times (when the external service controlling the switches was busy) the lights would fail to turn on. The timeout on updating the switch status is 10 seconds, so the bounce timer is set to 12 seconds and implemented like this:
- id: garage_lights-on-bounce-timer-finish
alias: "Check for garage lights on switch bounce"
initial_state: true
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.garage_lights_on_switch_bounce
condition:
condition: state
entity_id: group.garage_lights
state: 'off'
action:
- service: timer.start
entity_id: timer.garage_lights_on_switch_bounce
- service: homeassistant.turn_on
entity_id: group.garage_lights
So, if the lights are off when the bounce timer finished, the timer is started again and the lights turned on. This all works perfectly.
So, when the garage lights are turned on a 5 min timer is started to turn them off.
- id: garage-lights-on
alias: "Start timer when the garage lights are turned on"
initial_state: true
trigger:
platform: state
entity_id: group.garage_lights
to: 'on'
condition:
condition: state
entity_id: timer.garage_lights_timer
state: 'idle'
action:
service: timer.start
entity_id: timer.garage_lights_timer
And when this timer finishes…
- id: garage-lights-on-timer-finish
alias: "Garage light timer finished"
initial_state: true
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.garage_lights_timer
condition:
condition: state
entity_id: group.garage_lights
state: 'on'
action:
- service: timer.start
entity_id: timer.garage_lights_off_switch_bounce
- service: homeassistant.turn_off
entity_id: group.garage_lights
and the corresponding off bounce timer:
- id: garage_lights-off-bounce-timer-finish
alias: "Check for garage lights off switch bounce"
initial_state: true
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.garage_lights_off_switch_bounce
condition:
condition: state
entity_id: group.garage_lights
state: 'on'
action:
- service: timer.start
entity_id: timer.garage_lights_off_switch_bounce
- service: homeassistant.turn_off
entity_id: group.garage_lights
Here is where the problem lies…,
- Lights are turned on, either manually or via automation, no problem
- 5 min Timer starts
- 5 min timer finishes
- Only the first light in the group is turned off, however according to HA all three lights are off, and so is the group
- So, at this point 2 lights in the garage are still on, but HA says they are all off.
- After 1 minute the status of two of the garage lights changes back to on (they have been on the whole time)
- So, the 5 minute time restarts
- 5 minute timer finishes, switches off the group. Again exactly the same thing happens. The state of all three lights and the group is set to off, however the last two lights in the group remain on.
- This sequence then repeats forever until the lights are turned off manually either in the HA using the Lovelace interface, eWeLink app or physically using the actual switch (shocker…)
Suggestions ?