Hi!
I have an issue where Home Assistant reuse events when a device becomes available.
I have an external motion sensor that reports motion as events. This is the configuration it posts to MQTT:
{
"availability_topic":"hall/status",
"device_class":"motion",
"event_types":[
"motion"
],
"name":"Hall events",
"state_topic":"hall/event/events/state",
"unique_id":"hall_events"
}
Here is an automation I have to detect the event:
- id: 'movement_hall_0x00'
alias: 'Hall movement: On Motion'
mode: restart
trigger:
- platform: state
entity_id: event.hall_events
condition:
- condition: state
entity_id: event.hall_events
attribute: "event_type"
state: "motion"
action:
- choose:
# If light is off and its dark, turn on.
- conditions:
- condition: template
value_template: "{{ state_attr('event.hall_events', 'brightness') < states('input_number.hall_dark_when_below')|float }}"
sequence:
- service: scene.turn_on
entity_id: scene.hall_low
- service: switch.turn_on
entity_id: switch.mirror
- delay: 00:02:00
- service: switch.turn_off
entity_id: switch.mirror
- service: light.turn_off
entity_id: light.hallway
data:
transition: 2
This works well. On movement, the device publish an non retained message to hall/event/events/state
which trigger the automation. The message looks like this: {"brightness":0.02442002482712269,"event_type":"motion"}
If this device drops connection or restarts, without sending any new data except for publishing “online” again on the availability topic, home assistant will trigger the automation again as it detects an event.
I can simulate this by just publishing offline → online on the availability topic. The HA configuration and the state topic data is unchanged. Note that HA and MQTT are still running in this case, the only thing that changes is the value of the availability topic.
How can I prevent HA from reusing events in this case when a device becomes available?