Trigger automations when clicking ON even if button already is in state ON

Hi,

Is there any way to trigger an automation if I click “on” on a button even if the button’s state already is “on”?

As I understand it, the state machine won’t register any “on” signal if the entity already is in state “on”.

In the “developer tools - entities” there is an option to manually set any entity to any value. In that menu I can set my button (which is a ligth entity in HA) to “other” even if lights normally only can have state ON or OFF. So my thought was that I could make an automation that after any signal (ON or OFF) from that button always set the status to “other”. In such case HA will always act when clicking on any of the buttons (ON or OFF).

I tested to set the button in ON and my automation fired. Then I set the button’s state to “other” via the developer tool in frontend, and then I clicked ON again and the automation fired again, so it works that way. But I don’t know how to set the button state to “other” via an automation.

Can anyone help me with that or any other solution that will make HA to react even if I sent the same state as it already is in?

(My buttons are 433 RF link buttons by the way)

That would be really awesome!

/peter

What sort of button are you talking about?

Why set it to other?

Why not just turn it off?

Well, not directly.

a state trigger by definition only fires when the state changes on the entity. If you don’t specify a state, it will fire when a state or attribute changes.

What you can do is capture the service call that the button fires.

trigger:
  platform: event
  event_type: button_pressed
  event_data:
    entity_id: sensor.my_button
    state: 'on'

You’ll have to figure out what the event looks like. Open developer tools, go to events, and enter “button_pressed” and click ‘start listening’. Then push the button you want and see the event.

You basically try to match the event_data to the exact event you want. The less info here, the more generic the event will be. For example, if you don’t put any event_data, you’ll trigger on ALL button presses for all rflink devices.

I guessed on the state: on. I’m not sure what will be in the payload. You can figure this out from listening to the event.

Thanks a lot for your answers! I will look for events as soon as I can today and I will post my result (or more questions) here. You gave me big hope now :grinning:

Hi Tom. It’s a nexa switch that sends on 433 MHz and I detect it with rflink.

Oh I thought you were talking about lovelace.

As suggested, event triggers are what you want.

1 Like

Hi Jocnnor,

I was really inspired by your suggestion and I have tried it this morning but I’m not sure if I do the event listening correct. I can’t see any reaction at all even though I click my button and automations are triggered.

May I ask for some more instructions on how to do the listening and where I can expect to see the results?

I opened the deleloper tools - event and in the bottom of that page I write “button-pressed” and click on “start listening”. Then I click on the button and nothing happens in the event view.

It would be great to solve it.

button_pressed

I am not 100% sure what the event name is for rflink. I got this event from looking through the code, though I could be wrong.

EVENT_BUTTON_PRESSED = "button_pressed"
EVENT_KEY_COMMAND = "command"
EVENT_KEY_ID = "id"
EVENT_KEY_SENSOR = "sensor"
EVENT_KEY_UNIT = "unit"

Try it with a service I know works. Type in call_service, then try turning off a light from inside home assistant. You should open a new tab, or do it from a new device since when you change tabs, the event listener stops listening. There you can get an idea of what events would look like.

1 Like

Thanks! I tried your example and that worked, so now I know that the events can be listened to :-).

so I have to figure out how to listen to rflink events specifically now then? Any ideas of where I can start my search for that info? I’m a noob as you see.

Will keep you updated about my progress (or no progress).

/peter

Hi here,
there is also a config attribute in RFLink devices to fire HA events if a signal is received:

I suggest you to config your ¿switch? RFLink device with fire_event: true, it should fire the events even if there is no state change. Perhaps something like:

switch:
  - platform: rflink
    devices:
      your_deviceid_here:
        name: Your device name here
        fire_event: true
        ...

Then, in your automations (as @jocnnor said), you must listen for a button_pressed event.

Finally, it is important that you know what kind of command sends your device. It could be an on command, but also the allon command.

PS: It will be easier to help you if you show us yours device configuration.

Big, big thanks for your help all of you!!

Now it works!!! I’m really happy about this!

The trick was like javicalle wrote, i.e. to configure the rflink switch with “fire_event: true” in configuration.yaml and after that it worked fine with the suggested trigger from jocnnor i.e.

trigger:
platform: event
event_type: button_pressed
event_data:
entity_id: sensor.my_button
state: ‘on’

This has been bugging me for long time and at some occations I have tried to solve it without success and this time I wrote about the problem here. Really nice!!