Service mqtt.pushish error: required key not provided @ data['topic']

Hi everyone!

I’m trying to create a button that when is pressed publishes a MQTT message on a topic that will force my MQTT sensors to update.

Here’s the code for the button:

type: button
icon: 'mdi:refresh'
icon_height: 40px
show_name: true
tap_action:
  action: call-service
  service: mqtt.publish
  data:
    topic: forceSensorsUpdate
hold_action:
  action: none
name: Force MQTT Sensors Update

When I click on the button I get the following error:
Failed to call service mqtt/publish. required key not provided @ data['topic']

I find this quite strange since I’m already providing the topic. I also tried adding a payload just in case, but I had the same problem. Can anyone help me figuring out what I’m doing wrong? Thanks!

tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    topic: forceSensorsUpdate

You will also require a payload.

1 Like

Thanks Tom! That’s it. After adding the payload everything is working now.

  service_data:
    topic: forceSensorsUpdate
    payload: '1'
1 Like