Troubleshooting a Heating Thermostat Payload

Hello, I need help with a payload that I want to send to a heating thermostat. Its not important, but I want to understand how it works. So far, I have this code.

show_name: true
show_icon: true
type: button
name: Heizung +1
icon: mdi:thermometer
tap_action:
  action: call-service
  service: mqtt.publish
  data:
    evaluate_payload: false
    qos: 0
    retain: false
    topic: zigbee2mqtt/Wohnzimmer - Heizung Fenster/set
    payload: >
      {{ "{\"occupied_heating_setpoint\": " ~
      (state_attr('climate.wohnzimmer_heizung_fenster', 'temperature') | float +
      1) | int ~ "}" }}

However, when I press the button, I get the following error message: ā€œz2m: Invalid message ā€˜undefinedā€™, skippingā€¦ā€ What am I doing wrong?

Maybe someone can help in the future :slight_smile:

You canā€™t use templates in a Button Card.

Move the entire mqtt.publish action into a script.

alias: Increment Setpoint
sequence:
  - variables:
      msg:
        occupied_heating_setpoint: >
          {{ (state_attr('climate.wohnzimmer_heizung_fenster', 'temperature') + 1) | int(0) }}
  - service: mqtt.publish
    data:
      topic: zigbee2mqtt/Wohnzimmer - Heizung Fenster/set
      payload: "{{ msg | tojson }}"

Then make the Button Card call the script.

show_name: true
show_icon: true
type: button
name: Heizung +1
icon: mdi:thermometer
tap_action:
  action: call-service
  service: script.increment_setpoint 
1 Like

Wow, thanks for that I donā€™t know about that. Would it work with another card that supports templating in the same way I wrote the payload?

None of the standard set of cards supports templates except for the Markdown Card.

Various custom cards support templates.

1 Like

THX for ur help :blush:

1 Like