I have two lights walking into the basement. One wall mounted light half way down the stairs and another one at the ceiling when you come down the stairs.
Physically each of the lights is controlled with separate wall switches.
The light at the stairs is controlled by a switch either at the top or the bottom of the staircase. The light in the basement can only be controlled from a switch in the basement.
Now I have installed a Shelly 2.5 in the basement two control the two lights. The staircase lightswitches are running in detached mode and I am trying to get the following behaviour implemented:
Short press: Toggle the staircase light and toggle the basement light, if it was in the same previous state (i.e. if both lights are initially off, they should both be switched on with one button press, but if the basement light is already on, I do not want to switch it off with this action)
Long press: Toggle the basement light (this way I can turn off the basement light standing at the top of the stairs.
My current implementation is as follows:
- alias: Light - Downwards Staircase Lightswitch
id: 'Light_downwards_staircase_lightswitch'
trigger:
platform: event
event_type: shelly.click
event_data:
device: shellyswitch25-CAFEAFFE #Shelly 2.5 Flur UG
channel: 2 #Channel 2=Staircase
mode: restart
max_exceeded: silent
action:
- variables:
trigger_action: '{{ trigger.event.data.click_type }}'
- choose:
- conditions:
- '{{ trigger_action == "long" }}'
# Toggle Basement Corridor Lights from Staircase Switch
sequence:
- service: light.toggle
entity_id: light.corridor_basement
default: # '{{ trigger_action == "single" }}'
# Toggle Downwards Staircase Light
# Shelly is in detached mode to not switch power, but control the staircase lighting via Zigbee instead
- service: light.toggle
entity_id: light.staircase_down
- condition: template
value_template: "{{ states('light.corridor_basement') != states('light.staircase_down') }}"
- service: light.toggle
entity_id: light.corridor_basement
It does work, but not everytime. I assume it comes down to timing. The conditional evaluation may run just before the staircase light is toggled therefore being a 50/50 chance, that the condition is evaluating the wrong state.
Is it possible to run the condition to toggle the basement light before performing the default toggling of the staircase light?
Can I put a further choose level within the default action?
I guess optionally I could insert a little delay, but ideally the lights should be pretty much synced.