Ok, if the else statement should be included, then I suggest looking into turning the list around, so the else-statement will be in the other end of the scale.
Try to add “sensor hvac:” above the -platform line without indentation.
E.g. like this:
temperature_HVAC:
- platform: template
sensors:
temperature_HVAC:
friendly_name: "Garage_hall_HVAC"
unit_of_measurement: '°C'
value_template: >-
{% set t = states('sensor.pana_mek_outside_temperature') | float(0) %}
{% if 0.1 > t > -2.1 %} 18.5
....
It does not validate either, giving:
Integration error: temperature_HVAC - Integration 'temperature_HVAC' not found.
Do I need that second “temperature_HVAC” anymore?
You missed the sensor word in front, ie “sensor temperature_HVAC:”
And avoid capital letters!
Where in the configuration.yaml
file are you adding the Template Sensor?
You have defined a Template Sensor using the legacy format so it should be added to the sensor
domain.
sensor:
- platform: template
sensors:
weather_temperature:
friendly_name: "Temperature"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('weather.huoltom_a', 'temperature') }}"
Yes, the abovementioned example is in sensor domain, exactly as you show. I’m sorry I did not remember to include it the code sample.
And it works as such. However exactly the same code with “weather_temperature” replaced with “temperature_HVAC” does not.
BUT, as instructed by WallyR, using “temperatur_hvac” (without capitals) validates.
It looks like that was it!
Thank You all! Next I start to examinen the differences between legacy and modern configurations.
Somewhat it feels that it is not that easy to try to get a hold on these from the scatch, not that they are that difficult, but that they are not easy to find. E.g. with google I have bumped in the Templating -page countless times, but first time I saw Template -page was via 123 Taras’s link…
templating is not to be confused with template, the integration(s) that based off templating.
Moving to the next step. Seems to be that creating scripts is not even nearly what documentation says. In HA there isa a graphical UI, where there is only option to feed in numerical values.
The documentation has nothinng about the UI.
There is an option to use yaml-editor, but I cannot make anything to stick there and I’m running out of variations what to even try. The following works:
set_garage_hall_temp:
alias: Set Garage hall temp
sequence:
- service: climate.set_temperature
target:
device_id: c6d59cfa6cf443c19a372b6f317e22e7
data:
temperature: 26
mode: single
icon: mdi:air-filter
So, the question is: What should I feed in the script on the place of “26” to use there the value defined in configuration.yaml and discussed earlier in this thread?
There is also that data: which is in some threads adviced to change to data_template: but that has made no difference, other than of course made using graphical UI impossible.
Secondly, do I need something to trigger the script?
Yuo replace 26 with a sensor variable encased in double brackets, like
{{ states('sensor.weather_temperature') }}
The double brackets tells HA to put the value of the sensor in that place.
When you in other places in HA encounters brackets followed percent, ie {% some code %}, then its not a value that it is put in place, but an actually program step, that in some way is changing the execute, like
{% if (states('sensor.weather_temperature'))==20 %}
26
{% endif %}
This only puts 26 in if the sensor is actually 20.
OK, thanks.
Yes, I’m aware of the meaning of double brackets.
In my case code in configuration.yaml is this:
sensor:
- platform: template
sensors:
temperature_ghall_hvac:
friendly_name: "Garage_hall_HVAC"
unit_of_measurement: '°C'
value_template: >-
{% set t = states('sensor.pana_halli_outside_temperature') | float(0) %}
{% if 0.1 > t > -2.1 %} 18.5
{% elif -2.2 > t > -4.1 %} 19
{% elif -4.2 > t > -6.1 %} 20
{% elif -6.2 > t > -8.1 %} 21
{% elif -8.2 > t > -10.1 %} 22
{% elif -10.2 > t > -12.1 %} 23
{% elif -12.2 > t > -14.1 %} 24
{% elif -14.2 > t > -16.1 %} 25
{% elif -16.2 > t > -18.1 %} 26
{% elif -18.2 > t > -20.1 %} 28
{% elif -20.2 > t %} 29
{% else %} 17
{% endif %}
…and the corresponding script would look like this:
set_garage_hall_temp:
alias: Set Garage hall temp
sequence:
- service: climate.set_temperature
target:
device_id: c6d59cfa6cf443c19a372b6f317e22e7
data:
temperature: {{ states('sensor.temperature_ghall_hvac') }}
mode: single
icon: mdi:air-filter
Firstly, creating this kind of script seems not to work if i try to use HA graphical UI for script editing, although in yaml -mode. I needed to add it in text editor directly to scripts.yaml, otherwise it wouldn’t accept it. Script editor also tends to autocorrect things (wrongly). (Is there any documentation of this script editor UI?)
However, when reloading scripts after change, I get this in my log:
invalid key: “OrderedDict([(“states(‘sensor.temperature_ghall_hvac’)”, None)])” in “/config/scripts.yaml”, line 8, column 0
you have to quote single line templates. Make sure to use doulbe quotes because your template contains single quotes.
I’m sorry, but You lost me know… What do I have to double quote?
You say that “…template contains single quotes” Template is the upper one, right? And it validates.
Script is the lower code sample, do You mean that?
Should this:
temperature: {{ states('sensor.temperature_ghall_hvac') }}
…be like this:
temperature: {{ states("sensor.temperature_ghall_hvac") }}
Please look at this post:
OK, thanks, I take a look later. Duty calls…
OK, thank You, it was very enlightening reading.
Everything is working now. Including control for the second HVAC I have there.
However, when creating more scripts, HA seems to autocorrect the syntaxes, if they are even touched with graphical script editor. According to the links You provided, they probably wouldn’t work as such. I did not test this, though. Anyway, from now on, if any new scripts needed, I’d probably better off creating them manually.
Is this a known issue?
You can use the UI, it will change how it looks but it should still work.
Even though e.g.
temperature: "{{ states('sensor.temperature_ghall_hvac') }}"
…is automatically changed to
temperature: '{{ states(''sensor.temperature_ghall_hvac'') }}'
?
yep, that will still work.
OK, I stand corrected
Thank You all for great help!
Well well… It used to work just fine, but after latest 2021.12 updates I’m getting awful lot of these:
Error executing script. Unexpected error for call_service at pos 1: Invalid response, status code: 502 - Data: <html> <head><title>502 Bad Gateway</title></head> <body> <center><h1>502 Bad Gateway</h1></center> </body> </html>