Store value from mqtt event and only trigger if it changes

Hi, This automation triggers each time the shelly switch is pressed, via mqtt
The problem is, it also polls every 30 seconds so it triggers each 30 seconds as well

alias: shelly_test
description: ""
  - platform: mqtt
    topic: shellies/shelly1l-E8DB84AB4E5D/input/0
  - condition: template
    value_template: "{{trigger.payload != input_number.current_shelly_switch_input}}"
  - type: toggle
    device_id: b8ec72d8f44c0beca6bcfda68dbd0c57
    entity_id: light.luz_armario
    domain: light
  - service: input_number.set_value
      value: "{{trigger.payload}}"
      entity_id: input_number.current_shelly_switch_input
mode: single

I’m not sure if the condition works, and I’m not sure if I’m saving the payload value correctly in the input_number helper I created.

The payload it self is either a 0 or a 1

Hmm, i would approach it differently…

Create a sensor from mqtt (which subscribes to the topic)

And then use that sensor change to trigger your automation :wink:

@aceindy I didn’t think of that. working brilliantly now. so many options I forget about most!