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?
Thanks

You can create a sensor based on the topic:

sensor:
  - 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'
  trigger:
    platform: state
    entity_id: sensor.my_mqtt_sensor
  action:
    …

Great, thanks a lot