button-card
button-card copied to clipboard
Use templates in tap_action
I want to create a button that sends a MQTT command to raise a value by 1. However, when I use the javascript templates, they are submitted as plain text in the MQTT command.
Example Code:
tap_action:
action: call-service
service: mqtt.publish
service_data:
topic: command
payload: >-
{"CMD":0,"VALUE":'[[[ return
states["sensor.target_temp_c"].state+1]]]',"XTIME":0,"INTERVAL":0}
This creates the following MQTT command:
{"CMD":0,"VALUE":'[[[ return states["sensor.target_temp_c"].state+1]]]',"XTIME":0,"INTERVAL":0}
Sorry if I did something wrong, then I'd be happy for a correction. Thanks!
According to the documentation, tap_action cannot use templates.
But I too would need to use templates in the tap_action function.
My scenario:
Several buttons in a section have:
[...] tap_action: action: toggle
I added a button that enables all those in the section. So if the master button is disabled, all buttons below it must switch to:
[...] tap_action: action: none
According to the documentation, tap_action cannot use templates.
But I too would need to use templates in the tap_action function.
My scenario:
Several buttons in a section have:
[...] tap_action: action: toggle
I added a button that enables all those in the section. So if the master button is disabled, all buttons below it must switch to:
[...] tap_action: action: none
sure it can, see: https://github.com/custom-cards/button-card/issues/713#issuecomment-1628875427
Many tanks!!
@redfusion83, it should be:
tap_action:
action: call-service
service: mqtt.publish
service_data:
topic: command
payload: [[[ return `{"CMD":0, "VALUE": ${states["sensor.target_temp_c"].state+1}, "XTIME": 0, "INTERVAL": 0}`; ]]]