lucaorioli
(Lucaorioli)
December 15, 2019, 12:47pm
1
Hi, I hope somebody can help me: I want to change the target temp on a Generic thermostat using an automation. I have an input number called input_number.heating_temperature and into my automation I have set:
action:
data:
entity_id: climate.TermoPrimoPiano
hvac_mode: heat
temperature: “{{ states(‘input_number.heating_temperature’) | int }}”
service: climate.set_temperature
But this doesn’t do anything in my thermostat. If I change
temperature: "{{ states('input_number.heating_temperature') | int }}"
with
temperature: input_number.heating_temperature
Also doesn’t work.
It work only if I set a numeric value.
temperature: 19
I’m quite sure it’s a syntax error, but I can’t found where I wrong…
May you help me?
browetd
(Browet Didier)
December 15, 2019, 12:57pm
2
Here are some examples:
action:
- service: climate.set_hvac_mode
data:
entity_id: climate.courcelles
hvac_mode: 'heat'
- service: climate.set_preset_mode
data:
entity_id: climate.courcelles
preset_mode: 'home'
- service: climate.set_temperature
data_template:
entity_id: climate.chambre_t
temperature: '{{ states.input_select.t_chambre_thomas.state }}'
if you are using a template (like my third example), you must use “data_template:”
Search on google “templating home assistant” for more examples
4 Likes
lucaorioli
(Lucaorioli)
December 20, 2019, 1:18pm
3
Thank you very much, with data_template it works!
lucaorioli
(Lucaorioli)
December 29, 2019, 10:08pm
4
I’m sorry to disturb again but templating syntax is difficult for me.
I’ve to set an input number at different values depending on hours. So I have that:
input_number.target
input_number.pt_6_22 = 2
input_number.pt_6_23 = 1
where 6 is the day of week and 22 (or 23) the hour of day.
If, in my automation, I set value of input_number.target using this template:
{{ states.input_number.pt_6_22.state | int }}
it takes the correct value but if I want to nest into this template hour and day variables I can’t find which is the correct teplate. I want somenthing like this:
{{ states.input_number.pt_{{ now().weekday() }}_{{ now().hour }}.state | int }}
But it doesn’t work.
May you tell me which is the right syntax?
Thanks
browetd
(Browet Didier)
December 29, 2019, 10:31pm
5
Let’s try this:
{{ states('input_number.pt_{{ now().weekday() }}_{{ now().hour }}') | int }}
Let me know if it is working…
1 Like
lucaorioli
(Lucaorioli)
December 29, 2019, 11:29pm
6
It’s perfect! Thanks a lot!
1 Like
lucaorioli
(Lucaorioli)
December 30, 2019, 3:04pm
7
I’m really sorry, I try but I can’t resolve my bugs…
Another template:
{{ states(‘input_number.temp_{{ states.input_number.temp_p1.state | int }}’) }}
Should return the current value of input_number.temp_1 because
{{ states(‘input_number.temp_p1’) | int }}
returns 1, but it returns value “unknown” even if
{{ states(‘input_number.temp_1’) }}
Returns the correct value. of 20.0
What’s the difference in calling variables instead of functions?
That’s the last step to finish my programmable thermostat code that I want to share with the community…
Thanks a lot!
browetd
(Browet Didier)
December 31, 2019, 8:41am
8
I tried as well and I have the same behaviour (answer is “unknown”)
I do not see any solution sofar… You probably have to split this line by using “if… else… endif” to work around this double template cascade…
lucaorioli
(Lucaorioli)
December 31, 2019, 1:50pm
9
I’ve found the solution and, founding it, I found that your previous solution doesn’t really works.
The right format, that works, is:
“{{ states(‘input_number.temp_%s’ | format(states.input_number.temp_pt.state | int)) }}”
and:
“{{ states(‘input_number.temp_pt_%s’ | format(now().weekday() ~’_’~now().hour)) | int }}”
that ha formatted to:
temperature: '{{ states(''input_number.temp_%s'' | format(states.input_number.temp_pt.state
| int)) }}'
and:
data_template:
value: ‘{{ states(’‘input_number.temp_pt_%s’’ | format(now().weekday() ~’’_’’
~now().hour)) | int }}’
Also I had to put this code directly in yaml file because the grafical interface didn’t saved it.
1 Like
cfgroenewald
(Francois Groenewald)
October 31, 2020, 7:58pm
10
HI Guys
Apologies still cant seem to get this working. Very new to HA:
Config:
‘’
climate:
platform: generic_thermostat
name: geyser
heater: switch.sonoff_1000cf70ff
target_sensor: sensor.sonoff_1000cf70ff_temperature
min_temp: 15
max_temp: 70
ac_mode: false
#target_temp: 23.7
cold_tolerance: 0.2
hot_tolerance: 0.2
min_cycle_duration: 00:01:00
initial_hvac_mode: “off”
away_temp: 16
precision: 0.1
‘’
Automations:
‘’
id: ‘1588424152630’
alias: Geyser Week On - Slot1
description: ‘’
trigger:
platform: time
at: input_datetime.geyser_time_on_1
condition:
condition: time
weekday:
data: {}
entity_id: climate.geyser
service: climate.turn_on
service: climate.set_target_temperature
temperature: ‘{{ states(’‘input_number.temp_%s’’
format(states.input_number.geyser_temp1_week.state| int)) }}’
mode: single
‘’
input number = input_number.geyser_temp1_week
Any help would be greatly appreciated.
lucaorioli
(Lucaorioli)
November 1, 2020, 8:52am
11
My current working configuration is:
id: ‘1577728788647’
alias: Cron Temperatura PT
description: ‘’
trigger:
minutes: ‘*’
platform: time_pattern
condition:
action:
data_template:
hvac_mode: heat
temperature: ‘{% if is_state((’‘input_boolean.temp_pt_%s’’ | format(now().weekday()
~‘’_‘’~now().hour)), ‘‘on’’) %}{{ states.input_number.temp_1.state }}{%- else
%}{{ states.input_number.temp_2.state }}{%- endif %}’
entity_id: climate.termostato_pt
service: climate.set_temperature
I have one input_boolean for every hour of every day (input_boolean_temp_pt_0_0 for sunday at 00:00, input_boolean_temp_pt_0_1 for sunday at 01:00, input_boolean_temp_pt_1_0 for monday at 00:00, and so on) to decide if use target temp 1 or target temp 2, but I think you can safely remove the “if” leaving only something like this:
id: ‘1577728788647’
alias: Cron Temperatura PT
description: ‘’
trigger:
minutes: ‘*’
platform: time_pattern
condition:
action:
data_template:
hvac_mode: heat
temperature: ‘{{ states.input_number.temp_1.state }}’
entity_id: climate.termostato_pt
service: climate.set_temperature
Hope this can be useful!
cfgroenewald
(Francois Groenewald)
November 1, 2020, 2:19pm
12
Really struggling, still cant get mine to work:
Config.yaml
climate:
platform: generic_thermostat
name: geyser
heater: switch.sonoff_1000cf70ff
target_sensor: sensor.sonoff_1000cf70ff_temperature
min_temp: 15
max_temp: 70
ac_mode: false
cold_tolerance: 0.2
hot_tolerance: 0.2
min_cycle_duration: 00:01:00
initial_hvac_mode: “off”
precision: 0.1
away_temp: 15
Automation.yaml:
id: ‘1604233723655’
alias: Geyser Week On - Slot1
description: ‘’
trigger:
platform: time
at: input_datetime.geyser_time_on_1
condition:
condition: time
weekday:
data_template:
entity_id: climate.geyser
hvac_mode: heat
service: climate.set_target_temp
target_temp: ‘{{ states.input_number.geyser_temp1_week.state }}’
mode: single
I get the following error:
Invalid config for [automation]: must contain at least one of service, service_template. @ data[‘action’][0]. Got None. (See /config/configuration.yaml, line 10).
lucaorioli
(Lucaorioli)
November 1, 2020, 3:45pm
13
Are you editing the yaml file or into web interface? Maybe an indetation problem, your “action:”, “condition:” and “weekday:” lines seem to have too many spaces before “action:”, it should have only one space before like “trigger:”.
I’m not able to quote here the code with visible indentation but also entity_id, hvac_mode, temperature and maybe mode need 2 spaces more then data_template and service one only more.
Maybe thi
cfgroenewald
(Francois Groenewald)
November 1, 2020, 8:31pm
14
Please see indentation below, what do you think?
Blockquote
-id: ‘1604258012451’
alias: Geyser Week t1Aan
description: ‘’
trigger:
-platform: time
at: ‘22:22:00’
condition:
action:
data_template:
hvac_mode: heat
temperature: ‘{{ states.input_number.geyser_temp1_week.state }}’
entity_id: climate.geyser
service: climate.set_temperature
mode: single
Blockquote
Operrr
(Operrr)
April 1, 2025, 10:54pm
16
I control the thermostat using an encoder, I decided for myself using simple automation
alias: Encoder.Change target temp1
description: “”
triggers:
trigger: state
entity_id:
input_number.target_temp_heater1
conditions:
actions:
action: climate.set_temperature
metadata: {}
data:
temperature: “{{ states(‘input_number.target_temp_heater1’) }}”
target:
entity_id:
- climate.Heater1
mode: single