Hi,
I’m trying to clean up my automations since there have been a lot of changes lately to the features in automations.
I want to combine some on/off automations into a single one.
I’m using zigbee2mqtt for my switches.
Zigbee2mqtt will set the _action entitiy for example for an Ikea switch to on/off based on which button was pressed and immediately set it back to empty.
This is enough to trigger an automation.
Currently I have 2, one for turning the lights on and one for turning the lights off based on the button press.
The problem is when I try to combine on/off into a single automation and use the “choose” feature, this seems to not work reliably, (only 3 out of 4 times).
I’m assuming this is because the states are not cached, when I use them inside the choose section, and _action is already been set back to empty?
Is there a way to determine which trigger caused the automation to activate inside the choose section?
alias: new on-off
description: ''
trigger:
- entity_id: sensor.ikea_switch_action
platform: state
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: sensor.ikea_switch_action
state: 'on'
sequence:
- entity_id: 'light.stehlampe1'
service: light.turn_on
- service: mqtt.publish
data:
topic: zigbee2mqtt/tv_lampen/set
payload: '{"state": "on"}'
- conditions:
- condition: state
entity_id: sensor.ikea_switch_action
state: 'off'
sequence:
- entity_id: 'light.stehlampe1'
service: light.turn_off
- service: mqtt.publish
data:
topic: zigbee2mqtt/tv_lampen/set
payload: '{"state": "off"}'
default: []
mode: single