I am trying to set up a switch by template to perform multiple actions on turn_on and turn_off. The value_template is working but I can’t get any actions to run. Any ideas, please?
immersion1:
friendly_name: "Immersion 1"
unique_id: immersion1
value_template: "{{ is_state('climate.immersion_1_thermostat','on') }}"
turn_on:
- action: climate.set_preset_mode
target:
entity_id: climate.immersion_1_thermostat
data:
preset_mode: home
- action: climate.turn_on
data: {}
target:
entity_id: climate.immersion_1_thermostat
turn_off:
- action: climate.set_preset_mode
data:
preset_mode: away
target:
entity_id: climate.immersion_1_thermostat
- action: climate.turn_off
data: {}
target:
entity_id: climate.immersion_1_thermostat
- switch:
- name: Immersion 1
unique_id: immersion1
icon: mdi:water-boiler
state: "{{ is_state('climate.immersion_1_thermostat','on') }}"
turn_on:
- service: climate.set_preset_mode
target:
entity_id: climate.immersion_1_thermostat
data:
preset_mode: home
- service: climate.turn_on
target:
entity_id: climate.immersion_1_thermostat
turn_off:
- service: climate.set_preset_mode
target:
entity_id: climate.immersion_1_thermostat
data:
preset_mode: away
- service: climate.turn_off
target:
entity_id: climate.immersion_1_thermostat
value_template:
> state:
(new format)
- action:
> - service:
Mikefila
(Mike Fila)
May 3, 2025, 5:02pm
3
krskrab:
- action:
> - service:
It’s the other way around action
is the current key. They also need to add the platform: template
key and value.
switch:
- platform: template
switches:
immersion1:
value_template: "{{ is_state('switch.source', 'on') }}"
turn_on:
- action: switch.turn_on
target:
entity_id: switch.target
- action: light.turn_on
target:
entity_id: light.target
data:
brightness_pct: 40
turn_off:
- action: switch.turn_off
target:
entity_id: switch.target
- action: light.turn_off
target:
entity_id: light.target
https://www.home-assistant.io/integrations/switch.template/#multiple-actions-for-turn_on-or-turn_off
My configuration.yaml file contains the following line:
switch: !include switch.yaml
and the lines that I posted were cut out of my switch.yaml file which contains plenty of switches that work:
- platform: template
switches:
####################################
# for Immersion Heaters #
####################################
immersion_1:
unique_id: immersion1
value_template: "{{ is_state('climate.immersion_1_thermostat','on') }}"
turn_on:
- action: climate.turn_on
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_1_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: home
target:
entity_id:
- climate.immersion_1_thermostat
turn_off:
- action: climate.turn_off
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_1_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: away
target:
entity_id:
- climate.immersion_1_thermostat
immersion_2:
unique_id: immersion2
value_template: "{{ is_state('climate.immersion_2_thermostat','on') }}"
turn_on:
- action: climate.turn_on
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_2_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: home
target:
entity_id:
- climate.immersion_2_thermostat
turn_off:
- action: climate.turn_off
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_2_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: away
target:
entity_id:
- climate.immersion_2_thermostat
I actually used the HA page that you mentioned Template Switch - Home Assistant as the basis for code.
This is really confusing me as I have an automation which delivers the desired outcome and I just wanted a simple “manual” option for my dashboard.
alias: 18c. Predbat immersion control
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.predbat_iboost_active
from: "off"
to: "on"
id: iBoost_on
- trigger: state
entity_id:
- binary_sensor.predbat_iboost_active
from: "on"
to: "off"
id: iBoost_off
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- iBoost_on
sequence:
- action: climate.turn_on
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_1_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: home
target:
entity_id:
- climate.immersion_1_thermostat
- action: climate.turn_on
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_2_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: home
target:
entity_id:
- climate.immersion_2_thermostat
- conditions:
- condition: trigger
id:
- iBoost_off
sequence:
- action: climate.turn_off
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_1_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: away
target:
entity_id:
- climate.immersion_1_thermostat
- action: climate.turn_off
metadata: {}
data: {}
target:
entity_id:
- climate.immersion_2_thermostat
- action: climate.set_preset_mode
metadata: {}
data:
preset_mode: away
target:
entity_id:
- climate.immersion_2_thermostat
mode: single
So,after building some screens, it looks like the switch works insofar as it turns the immersion heater on, but the displayed status of the climate helper doesn’t reflect that.
So what I really need to achieve is to get the climate helper and card to reflect the current situation.
This looks a lot like this thread
Thermostat Card Buttons Not Updating? so I probably need to close this one and head on over there. Thanks.