Hello,
I want to make an automation that
- turn light on, on movement detection
- turn light off after no movement detection.
I’m using a Xiaomi sensor, i.e. http://nl.aliexpress.com/item/32975225751.html
The problem was
- if you make a movement
- the light turns on
- if you turn the light off with another manual trigger (let’s say another switch somewhere in the room)
- and you move again
than - the light was NOT turn on again
because - there was no change in state
This is because the state remains for approx 2min.
So if you make a movement, the state of the “occupancy” is “on”.
You turn off the light with the other switch and make a movement again: the sensor reports “on” again, but this is not a change.
I solved this with
# -------------------------------------------
- id: '0x00158d0003cf46ab_occupancy_if_true'
alias: (O03) Occupancy true already
trigger:
- entity_id: binary_sensor.0x00158d0003cf46ab_occupancy
platform: state
condition:
- condition: state
entity_id: binary_sensor.0x00158d0003cf46ab_occupancy
state: 'on'
action:
- service: light.turn_on
entity_id: light.0x14b457fffe51a9f2_light
data:
transition: 2
# -------------------------------------------
- id: '0x00158d0003cf46ab_occupancy_to_false'
alias: (O03) Occupancy false
trigger:
- entity_id: binary_sensor.0x00158d0003cf46ab_occupancy
platform: state
to: 'off'
for:
minutes: 0
action:
- service: light.turn_off
entity_id: light.0x14b457fffe51a9f2_light
data:
transition: 1
so, as you can see: the first trigger turns on the lights, not on change state “on”, but on every state, if state is “on”. Subtile difference, but this implementation this what I want.
However, on my MQTT messages, I see a double set-command…
Is the above automation a good implementation?
Can the double mqtt-message be avoided?
kind regards,
bart