Is it possible to nest variables in payload?

I meant that the pasting seemed to work, not the code. It still locks up Hass. But I see another problem here. Your new code is still on the states.sensor.termostat. but I am looking for something in another entity, as I’ve said, states.climate.termostat.

ok, just realised you have extra " in your template…
You also need quotes for your topic…
Try this:

- alias: Gulvtemperatur med modus
- action:
    data_template:
      payload_template: "{{'states.sensor.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air.attributes.operation_mode'}}"
      topic: "eg/Gulvtemperatur"
    service: mqtt.publish

Hopefully that’s the one :slight_smile:
(may need to watch your indentation though)

Thanks, but I’m afraid not. It doesn’t lock up Hass, but it doesn’t show the result of the variable either. I must repeate that it’s not states.sensor. but states.climate I’m after. So the payload in this latest version would be:

payload_template: "{{'states.climate.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air.attributes.operation_mode'}}"

(There are no line feeds in the code, is there supposede to be, so that was eaten by the forum software?)

But the result that comes through MQTT as the payload is:

states.climate.termostat8_dry_air.attributes.operation_mode

So it’s the concatenaded code in the brackets that’s sendt, and not the contents of the variable, which would be Heat.

Thanks, still trying to build this up for you, never actually did something quite lie this yet.
What if you relace
payload_template: "{{'states.climate.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air.attributes.operation_mode'}}"
with this:
payload_template: "{{state_attr('climate.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air', 'operation_mode')}}"

YEEEEEEEEEEESSSSSSSSSSSS!!! :rofl: IT WORKS! And I’ve spent four days trying to get this to work! Thank you very much! And with that I thought I could easily put together the whole package. Only one hitch left… This works:

  payload_template: "{{state_attr('climate.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air', 'operation_mode')}},{{trigger.from_state.attributes.node_id}},{{trigger.from_state.state}}"

It gives me the correct mode, Z-wave node ID and the current temperature.

eg/Gulvmodus u"Heat,3,23.5"

The other thing I was going to add was the zone number (which is the one used to get “heat”, so I tried this:

  payload_template: "{{state_attr('climate.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air', 'operation_mode')}},{{trigger.from_state.attributes.node_id}},{{trigger.from_state.state}},{{trigger.from_state.attributes.friendly_name.split(" ")[1]}}"

But for some reason that does not work. It locks up HA. Is it because I can’t use one variable in two places, or something?

Same again, you have double quotes (") inside your string.
replace the double quote with a single quote and you’re good to go
Basically make sure you only have 2 double quotes to delimit your entire string, one at the beginning, one at the end.
Anything between these 2 double quotes must be single quote else it’ll break…
payload_template: "{{state_attr('climate.termostat'+trigger.from_state.attributes.friendly_name.split(' ')[1]+'_dry_air', 'operation_mode')}},{{trigger.from_state.attributes.node_id}},{{trigger.from_state.state}},{{trigger.from_state.attributes.friendly_name.split(' ')[1]}}"

Ah, this syntax really manages to confuse me every time! :blush: But now I have it where I want to have it! Thank you very much again for your help and patience!

1 Like