custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.95k stars 236 forks source link

mqtt.publish does not work with custom button cards. #638

Open p4r4d0xs opened 1 year ago

p4r4d0xs commented 1 year ago

Hey folks,

i wanted to add a Picture for my button with mqtt.publish. so i install your custom cards button addon in HACS.

But when i copy the working mqtt.publish from the standard type: Button to your type: custom:button-card it dosent work anymore.

here is my working button card:

show_name: true show_icon: true type: button tap_action: action: call-service service: mqtt.publish data: topic: zigbee2mqtt/Weihnachtsbaum /set payload: >- { "effect": { "effect": "snow", "speed": 30, "colors": [ { "r": 255, "g": 255, "b": 255 } ] } } target: {} icon: hacs:hacs name: Schneeeffekt

now i add the custom button card

show_name: true show_icon: true type: custom:button-card tap_action: action: call-service service: mqtt.publish data: topic: zigbee2mqtt/Weihnachtsbaum /set payload: >- { "effect": { "effect": "snow", "speed": 30, "colors": [ { "r": 255, "g": 255, "b": 255 } ] } } target: {} icon: hacs:hacs name: Schneeeffekt

and now i get this error message: Fehler beim Aufrufen des Diensts matt/publish. must contain at least one of topic, topic_template.

not working 11 working 22

RomRider commented 1 year ago

The format is different in button card, you should be using service_data instead of data and not target also. Check the documentation for examples