I’m not very experienced with MQTT, so this could be a stupid question.
Anyway I have a body movement sensor and a simple light bulb which send their states through MQTT. I want it to check for no movement, and then turn off the light (and on when true).
This is how I currently have the automation set up:
- id: '123456789'
alias: light bedroom2
trigger:
- platform: mqtt
topic: zigbee2mqtt/movement_sensor_room_x
condition:
condition: template
value_template: "{{ trigger.payload_json['occupancy'] == false }}"
action:
- data:
payload: 'OFF'
topic: zigbee2mqtt/light_bedroom_2/set
service: mqtt.publish
It however does pretty much nothing.
This is the payload of the sensor:
{"occupancy":false,"linkquality":73,"battery":100,"voltage":3025}
And of the light:
{"state":"ON","linkquality":70,"brightness":254}
I’ve also tried something like this which also didn’t work:
automation:
trigger:
platform: mqtt
topic: zigbee2mqtt/movement_sensor_room_x
payload: '{"occupancy":false}'
action:
service: mqtt.publish
- data:
payload: 'OFF'
topic: zigbee2mqtt/outlet_livingroom/set
I’m pretty sure the error is in this bit: value_template: “{{ trigger.payload_json[‘occupancy’] == false }}” but quite frankly I’m not sure how to fix it. Any ideas?