MQTT and a dash button switch automation

Hi there,

I’m pretty new to this and I’m a little overwhelmed, also I’m not too good at scripting and understanding these thing due to the sheer overwhelming functionality.

I have set up a HA instance on my server, configured all switches, lights and stuff. Now I’m trying to trigger a rc outlet with a dash button, therefore I’ll setup mqtt-dasher. The button press is registered fine but I’m struggeling to get the automation running. After hours of unsuccessfull try and error I’m seeking for some help. Last thing I came up with is something like this:

mqtt gives me this: [hbmqtt.broker] broadcasting {‘session’: Session(clientId=mqttjs_8f5f3e7e, state=connected), ‘topic’: ‘dash1’, ‘data’: bytearray(b’active’)}

automation:
   trigger:
      platform: mqtt
      topic: "dash1"
      payload: "active"
      retain: "true"
    action:
      service: switch.toggle
      entity_id: switch.DeskRGB

But no luck so far. Can someone point me in the right direction? Thank you!

I’m not sure, but a little more try and error seems to do the trick, at least it works with this configuration:

  action:
  - service: switch.toggle
    entity_id: switch.deskrgb
    alias: dd
  condition: []
  trigger:
  - payload: active
    platform: mqtt
    topic: dash1

Maybe someday I’ll understand what I am doing here :wink:

The “retain” flag is typically used when configuring an mqtt component, not in your trigger. The “retain” pertains to the message that home assistant publishes, so it doesn’t make sense for your trigger (that home assistant is receiving to specify that). I suspect that that is the problem with your first attempt.