How to trigger automation with one status sensor

Hello all,

Does anyone know a way to trigger automation whenever a sensor has only one sensor status?
I have Airam fire detector and it works OK, but only sends ‘Panic’ whenever I test it.

I tried to change the state manually but the state changes back to Panic after a few seconds… (loads from some db or smth?)
I also tried to keep ‘to’ & ‘from’ fields empty to get all state triggers but it seems that the state needs to change…

Any help would be appreciated!

alias: Notify if garage fire alarm is triggered
  description: ''
  trigger:
  - entity_id: sensor.garage_fire_detector_sensor_status
    platform: state
  condition: []
  action:

This works one time after HA reboot as the status is unknown and then changes to Panic.

Sensor is added by using auto add of rfxtrx, then checked the id of this device and added under devices.

- platform: rfxtrx
  automatic_add: true
  devices:
    082003044b86000650:
        name: Garage fire detector
        data_type:
            - Sensor Status

In dev-tools states tab I can see this sensor having this kind of attributes

Your automation will trigger every time the state of that sensor changes. Which, is a good thing right? I don’t know if the status will change to another state after some time period elapses. But if it doesn’t ever reset its status, it sounds like there is a simple work-around, DON’T LIGHT THINGS ON FIRE! :wink: Actually, the simplest work-around would be to restart Home Assistant to clear the previous status.

If you push the test button a second time does the sensor at least have a new last updated time? If so you might be able to set a secondary trigger to when the last updated time changes?

There seems to be no last_triggered field with this one of course.

Yes it’s a good thing HA works like this most of the time but why no option to allow any state (same or different) to trigger the rule.

Try the following in the /developer-tools/template page. I believe it should tell you the last time your sensor updated.

{{ states.sensor.garage_fire_detector_sensor_status.last_updated }}

Now I’m not entirely sure this will work… but you may be able to trigger your automation every time the sensor updates, and you can use a condition to verify the value is “Panic” before taking action.

alias: Notify if garage fire alarm is triggered
  description: ''
  trigger:
    - platform: template
      value_template: "{{ states.sensor.garage_fire_detector_sensor_status.last_updated }}"
  condition:
    - condition: state
      entity_id: sensor.garage_fire_detector_sensor_status
      state: "Panic"
  action:

I’ve never tried triggering with a last_updated property before, but that is what I would try first.

the main question here is how is your sensor.garage_fire_detector_sensor_status created? what creates it?
when you tell us that, it’s possible to think about a solution. if you just change a sensor’s state in HA, it might revert back and you have no control over it so that’s not the right way.

Tried your idea as it seemed a possible solution, but…
last_updated -> “Time the state was written to the state machine in UTC time. Note that writing the exact same state including attributes will not result in this field being updated.”

So as the state stays the same last_updated will not get updated and trigger will not fire.

I edited the first post containing more info about the addition of this sensor.

I’m a bit lost here.
You have a fire detection sensor.
Which presumably you want to trigger a set of actions when it detects a fire.
You’ve read the documentation and both that and a manual test (button) produces “panic”

Why are you bothering with overcomplicating this? Just use to: ‘panic’ in the trigger
What have I missed ?

Somehow my example omitted the {{ }} that needs to surround the value in the value_template line. Look at Ny example above again, I corrected it.

Dear Muttley, you have missed that whenever the state is not changed it doesn’t trigger the automation. Of course I first tried just this what you described but it doesn’t work because the state doesn’t change.
It’s hard to understand why this kind of scenario is not taken into account with HA that maybe some sensors send only one status.

Move your sensor to binary_sensor and add an off_delay.

1 Like

Brian you are right, that mistake I did not notice.

value: "Panic" 

should be instead if i’m not mistaken

state: "Panic"

and that I did fix already.

But still I checked from the dev-tools template that the last_updated did not change after the first “Panic” so even with this fix I think it will not work.

This sounds promising will try that one next. Thanks for the hint!

S4mmy,
That is the way HA works,
It doesn’t put a light on because ‘this’ switch is on
It puts this light on because it sees that this switch has changed to on.
If it’s on already nothing happens.

We could create an automation that fires every minute to check the sensor and if it is in panic then put the light on but what would be the point?
a) you may be anything upto 59 seconds late
b) if you trigger it on the change you get it instantly and it reduces processing by, well 1,440 (the minutes in a day)

So I’ll ask again, what is the problem that you are trying to overcome with automation and what do you want to happen. What am I missing ?

If the ‘test button’ changes the state to panic, what does it change it ‘from’ ? ie what is the normal state ?

There is no “normal” state for this entity. The state is always “panic”. Some sensors only send a “open” (or in this case “panic”) event. That’s why he wants to trigger if the state changes even if it is the same state.

This can be solved by the method that @francisp suggested. There you can configure the sensor as a binary sensor and add an off delay in order to turn the sensor off after a specific time following the “panic” event.

Ah !

Buy a ‘proper’ sensor - or roll your sleeves up and get dirty with code.

This is like Gaurdians of the Galaxy where, one character only ever says ‘Groot !’ for everything and in all situations

1 Like

There was a fire_event variable also for rfxtrx sensor… (why I didn’t see this immediately!? :smile:)
“Fires an event even if the state is the same as before. Can be used for automations”
Of course now I have the sensor always in panic mode but now I get a message whenever alarm is triggered which is fine.
I couldn’t get the binary sensor to work, maybe it needed manual command_on variable and I was not sure how to set that correctly. automatic_add did not work with binary_sensor.

Thanks for all the help.

1 Like