HaoleBoy
(Jay)
January 6, 2024, 3:01pm
1
I’m trying to change the temperature setting of 3 different thermostats. just can’t get it to work
I need to pass two variables to the script
thermostat name
template sensor value (current temp setting) to know the starting point
my thermostats are thermostat, thermostat_2, thermostat_3
yaml call from my floorplan.
“sensor_value” is the variable I’m trying to use for the current temp setting
- element: set_temp_down_second
entity: script.adjust_temp_test
tap_action:
- service: script.turn_on
data:
thermostat: themostat_2
sensor_value: sensor.thermostat_ground_tempsetting
My script
adjust_temp_down:
sequence:
- service: climate.set_temperature
target:
entity_id: thermostat
data:
temperature: '{{ states(" {{ sensor_value }}") |float(70) - 2 }}'
pedolsky
(Pedolsky)
January 6, 2024, 3:38pm
2
Your script contains several errors. You have to use variables as follows:
sequence:
- service: climate.set_temperature
target:
entity_id: "{{ thermostat }}"
data:
temperature: "{{ states(sensor_value) |float(70) - 2 }}"
Frontend:
service: script.turn_on
data:
variables:
thermostat: climate.your_climate
sensor_value: sensor.your_sensor
target:
entity_id: script.1_test_thermostat
HaoleBoy
(Jay)
January 6, 2024, 4:19pm
3
I get this error
“Failed to call service script/turn_on. must contain at least one of entity_id, device_id, aread_id”
script
adjust_temp_test:
sequence:
- service: climate.set_temperature
target:
entity_id: "{{ thermostat }}"
data:
temperature: "{{ states(sensor_value) |float(70) - 2 }}"
front end:
- element: set_temp_down_second
tap_action:
service: script.turn_on
data:
variables:
thermostat: climate.thermostat_3
sensor_value: sensor.thermostat_second_tempsetting
target:
entity_id: script.adjust_temp_test
123
(Taras)
January 6, 2024, 4:41pm
4
- element: set_temp_down_second
tap_action:
action: call-service
service: script.adjust_temp_test
data:
thermostat: climate.thermostat_3
sensor_value: sensor.thermostat_second_tempsetting
pedolsky
(Pedolsky)
January 6, 2024, 5:18pm
5
I don’t know what card type this is containing - element:
, I’ve tested with a default button card.
See here for the differences between the service calls script.turn_on
and script: script.whatever
: https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts
My whole working config is
type: button
tap_action:
action: call-service
service: script.turn_on
data:
variables:
thermostat: climate.wohnen
sensor_value: sensor.temp_diele
target:
entity_id: script.1_test_thermostat
HaoleBoy
(Jay)
January 6, 2024, 5:43pm
6
thanks for the assistance, got it working.
I am using a Floorplan card.
scripts.yaml
adjust_temp_down:
sequence:
- service: climate.set_temperature
target:
entity_id: "{{ thermostat }}"
data:
temperature: "{{ states(sensor_value) |float(70) - 2 }}"
Floorplan card
- element: set_temp_down_second
entity: script.adjust_temp_down
tap_action:
- service: script.turn_on
service_data:
variables:
thermostat: climate.thermostat_3
sensor_value: sensor.thermostat_second_tempsetting
123
(Taras)
January 6, 2024, 6:27pm
7
Seems like what I had suggested except it uses service_data
, which Home Assistant’s native cards used to use and still support instead of the newer data
.
Is variables
necessary? Even the examples in Floorplan card’s documentation don’t use it.
pedolsky
(Pedolsky)
January 6, 2024, 6:35pm
8
If you want to pass variables, script.turn_on
only works with variables
.
123
(Taras)
January 6, 2024, 6:50pm
9
Unless there’s a design requirement to call script.turn_on
, calling the script directly eliminates the need for the variables
key.
Passing variables to scripts
Unclear why HaoleBoy’s example uses the more verbose way of calling the script. The subtle difference between the two calling methods is one waits for the script to complete whereas the other doesn’t. However, that difference is irrelevant for this application (button press; one short action).