Automation: run every time a (mqtt) sensor receives a value, even when it's the same value as previous value

Hi everyone,

Probably a stupid question, but I’ll give it a try.
I’m experimenting with Sonoff RF bridge + tasmota to use small RF-remotes to toggle my lights.

I have created an automation that works: If I push button “A” on my remote, it sends code “FF5F71” to the RF receiver, and my lights toggle:

- id: sonoff_rfbridge_FF5F71_mqtt
    alias: sonoff_rfbridge_FF5F71_mqtt
    trigger:
      - platform: mqtt
        topic: "tasmota/tasmota-112/tele/RESULT"

        payload: "FF5F71"
        value_template: "{{ value_json.RfReceived.Data }}"
    action:
    - data:
        entity_id: light.group_n00_p00
        transition: 0
      service_template:
        homeassistant.toggle

Now I want to be a little bit more organized:

  1. define a sensor that reflects the RF-value
  2. toggle the light, everytime the sensor receives a value.

So I defined

Sensor
- platform: mqtt
    name: "Sonoff RF bridge: RfReceived.Data"
    state_topic: "tasmota/tasmota-112/tele/RESULT"
    value_template: "{{ value_json.RfReceived.Data }}"
    icon: mdi:chip

Grreat! I can see the RF-value on my dashboard.

However, if I create an automation like

- id: sonoff_rfbridge_FF5F71
    alias: sonoff_rfbridge_FF5F71
    trigger:
      - platform: state
        entity_id: sensor.sonoff_rf_bridge_rfreceived_data
        to: "FF5F71"
    action:
    - data:
        entity_id: light.group_n00_p00
        transition: 0
      service_template:
        homeassistant.toggle

it only toggles my lights if there is a change in state.
So if I want to toggle my lights: I first have to press another button, and than my button “A” again. So by simply pressing “A”, my sensor does not change it’s value, so the automation is not triggered.

Any suggestions how I could achieve this?
Thus: every time a sensor gets a certain value, trigger an automation? Even when the received value is the same as the previous value?

sorry for my ignorance,

kind regards,
Bart Plessers

1 Like

Keep the sensor for display, but go back to using the mqtt trigger.

The MQTT integration ignores duplicated payload values (do what tom_l suggested)

1 Like

To be precise, that’s basically true for all integrations.
At low level, HA ignore entity state & attributes changes if the new ones are exactly the same as the previous ones.

1 Like