Cannot get a switch template working

Hi guys,
I have been trying to create and test a switch template using UI but have an issue.
I can turn on/off the template manually, but it does not pass on/off testing.
Also system log shows warning every minute if I use the switch template in thermostat.
Can anyone help? Thanks!

Value template:

{{ is_state_attr('climate.thermostat_1', 'hvac_action', 'heating') }}

Turn on action:

action: climate.set_temperature
data:
  temperature: 30
target:
  entity_id:
    - climate.thermostat_5
    - climate.thermostat_4
    - climate.thermostat_1
    - climate.thermostat_3
    - climate.thermostat_2

Turn off action:

action: climate.set_temperature
data:
  temperature: 10
target:
  entity_id:
    - climate.thermostat_5
    - climate.thermostat_4
    - climate.thermostat_1
    - climate.thermostat_3
    - climate.thermostat_2

Hello initguru,

I believe your indentation on the YAML is wrong. I would look there.

Please share the template switch configuration as text formatted for the forum. Not as a picture. Use the </> button in the post toolbar to format your pasted config.

I would like to, but it is created on UI so I don’t know if I can get plaintext version of the template.

I made this on the UI so that indent were automatically put by the system. I checked and they are okay. I’m not sure what the error is: "not a valid value for dictionary value @data[‘entity_id’]

View as yaml, and share that as Tom suggested.

thanks, I edited the post, please look at it!

I’m sorry, I have to bow out on this.

I have like 20 templates but all were written in YAML.
I tried to create one in the GUI and have NO IDEA how.
I can see stuff about my YAML ones but not any of the Code.

The only think I can think of is you are saying :

Sometimes at least in the automation and script GUI you can’t test using the tool, you have to use developer - states to change the actual value of the sensor to force a test trigger.

That’s all I got.

Try putting the actions in as a list. e.g.

- action: climate.set_temperature
  data:
    temperature: 30
  target:
    entity_id:
      - climate.thermostat_5
      - climate.thermostat_4
      - climate.thermostat_1
      - climate.thermostat_3
      - climate.thermostat_2

I have tried before and that kind of manual test all worked well… Actually, at the beginning I also created this switch in configurations.yaml and it didnt work too. :frowning:

Im sorry tom, but I cannot see any difference between your code and mine. Actions as a list how?

Look closer.

Screenshot 2025-01-15 at 14-34-28 Cannot get a switch template working - Configuration - Home Assistant Community Screenshot 2025-01-15 at 14-34-54 Cannot get a switch template working - Configuration - Home Assistant Community

I got it, but after I modified the code entity is not recognized and I got another error…

Ok you cant do that. Go back to what you had. I missed the “Add Action” button below. The helper builds the list for you if you have more than one action.

It seems to be complaining about the entity ID. Does it work if you just set one temperature, like this?

action: climate.set_temperature
data:
  temperature: 30
target:
  entity_id: climate.thermostat_5

If it does, you could add the other four as additional actions.

What does it look like in the visual editor? My attempt:

1 Like

I tried that before but it shows the same error… thanks anyway.

Can you pass on/off testing by touch the toggle button at the bottom? (name would be ‘test’)

Interestingly no, I also get that error:

However, the switch works, changing the temperature between 15 and 16 in my example, without generating any errors in the logs.

I wonder if you’re having problems because the actions you are taking do not result in a change to the value template?

Actually ‘run action’ works well and manually set a value from developer setting works well too.
I would like to use this switch to turn on/off all climate entities, from another general climate entity.
Problem happens here. That general climate entity cannot use the switch.
Error in the system log says:

Logger: homeassistant.helpers.service
Source: helpers/service.py:303
First occurred: 3:16:32 PM (252 occurrences)
Last logged: 6:27:12 PM

Referenced entities switch.hcm_valves are missing or not currently available

The logic of your state / value_template feels weird/flawed to me. Surely it should be based on which temperature the HVAC is set to, not on whether it is currently heating or not?

Ponder this: The HVAC is already set to 10°, the temperature drops further and heating kicks in. Now the switch will show that the HVAC is “on”, but if you click the switch to toggle it “off” the switch will never flip to the “off” position. The HVAC is already set to 10° but the temperature is below that, so it will continue heating until reaching the set temperature. Seems like a very unintuitive UX to me.