Publish mqtt msg in lovelace?

Hello,

I want to have the hold action for a switch publish a mqtt message. I have the following in lovelace but no message is being published. When I call the service (mqtt.publish) under developers tools and enter the json data it does work. I looked at the docs and this does seem possible but I’m not sure if it’s formatted correctly. Does anyone have a suggestion?

  - entity: switch.sw_hal_main
    hold_action: call-service
    service: mqtt.publish
    service_data:
      topic: cmnd/sw_hal_main/POWER1
      payload: HOLD
    image: /local/button.png
    style:
      left: 32%
      top: 65.5%
      width: 10%
    tap_action:
      action: toggle
    type: image

Assuming your topic/payload are correct, try this indentation with the hold_action:

      hold_action:
        action: call-service
        service: mqtt.publish
        service_data:
          topic: cmnd/sw_hal_main/POWER
          payload: HOLD
2 Likes

AHHHHHH.

I did

hold_action: call-service

not

hold_action: 
  action: call-service

Thank you, Your suggestion was perfect.