MQTT edge detection - trigger automation when payload changes

Hi All
I have a MQTT topic that gives me the input state of a shelly device. I want to use edge detection to toggle lights when the status of this payload changes. I can’t see any way of comparing the payload of a MQTT message to the previous value. Is there any way to do this in HA?

You can create a sensor based on the topic:

  - platform: mqtt
    name: My MQTT Sensor
    state_topic: 'your/shelly/topic'

And an automation that triggers on state change:

- alias: 'Trigger on Shelly state change'
    platform: state
    entity_id: sensor.my_mqtt_sensor

Great, thanks a lot