Hello.
I’m looking for help with a proper answer. I have automation to turn swith on (MQTT Swtich) when message under topic “zigbee2mqtt/xiaomi_motion_sensor” will contain occupancy true and only if sensor state is off.
- alias: "Kitchen light ON (motion sensor)"
trigger:
platform: mqtt
topic: "zigbee2mqtt/xiaomi_motion_sensor"
condition:
condition: and
conditions:
- condition: template
value_template: "{{ true == trigger.payload_json.occupancy }}"
- condition: state
entity_id: binary_sensor.xiaomi_motion_binary_sensor
state: "off"
#also tried condition template and value_template: "{{ is_state('binary_sensor.xiaomi_motion_binary_sensor', 'off') }}"
action:
service: mqtt.publish
data_template:
topic: "cmnd/sonoff/power"
payload: "on"
And this automation doesn’t work.
The reason is condition. Proper message is send to “zigbee2mqtt/xiaomi_motion_sensor” but automation is not triggered because this part of condition doesn’t met:
- condition: state
entity_id: binary_sensor.xiaomi_motion_binary_sensor
state: "off"
If I remove this small part, then automation works well.
This is my binary_sensor (motion sensor from xiaomi aquara products which working via zigbee2mqtt. Payload on/off is true/false but status of this binary_sensor is on/off):
- platform: "mqtt"
name: "xiaomi_motion_binary_sensor"
state_topic: "zigbee2mqtt/xiaomi_motion_sensor"
availability_topic: "zigbee2mqtt/bridge/state"
payload_on: true
payload_off: false
value_template: "{{ value_json.occupancy }}"
device_class: "motion"
HA -> Developer Tools -> Templates shows me correct status for binary_sensor.xiaomi_motion_binary_sensor so I don’t understand why automation doesn’t work…
I suppose that my “and” condition is looking for state change. So It will work when proper mqtt message arrive AND state for my binary_sensor will be changed from something to “off”.
I’m not 100% sure about it, this is only my speculation.
If this is correct then how I can check status in conditions? I want to trigger this automation when message arrive and if binary_sensor have “off” status. Any idea?