I’m new to this so any help is more than welcome and I apologize in advanced if I make anything wrong.
What I want to do:
I have 2 temperature sensors (Shelly HT) in different areas of the house. I want to turn on a plug if one of them falls below a given temperature defined in input_number.termometro_test, but only during a period of the day specified by input_datetime.horario_inicio & input_datetime.horario_fim.
Since I have no YAML experience, I’m working with the UI as much as possible (Variables where created in the UI and also the automation). I then tried several different solution in the UI and by editing the automation.yaml.
My issue is:
Everything works if in the condition I use a value such as “18”, everything I tried with the “input_number.termometro_test” does not work.
I tried:
below: 18 => Works
below: input_number.termometro_test => Does not work (edited in “automations.yaml”)
below: "{{ states('input_number.termometro_test') | int }}" => Does not work (edited in “automations.yaml”)
below: "{{ states('input_number.termometro_test') | int(0) }}" => Does not work (edited in “automations.yaml”)
Theoretically, the first one should have worked because a Numeric State Condition does support assigning a Helper (such as an input_number) to its above and below options. Here’s the last example from the documentation:
The other two are invalid because it does not allow its below and above options to have templates.
EDIT
I see the problem. Your example is using a Device Condition, not a Numeric State Condition. Device Conditions aren’t even documented; they are created via the UI and it’s best not to edit them afterwards. Use a Numeric State Condition and assign it the input_number but don’t try to create a template because it’s not supported for below.
I tried several things in the UI, and it seems that whenever you put something in Above or Below that is different of an actual number, you get error messages and nothing is saved to automation.yaml (this happened both in device and in numeric_state)
The Template solution worked straight out of the UI. It behaves a bit strange because it does not fire when the trigger happens but about 20-30sec later. This is not a problem in this case, but I can imagine that this could be an issue in some aplications.
Might be a bug but the UI does not allow you to insert a helper in above or below. When you try to save it, the UI gives out an error and nothing is saved.
BTW, given that you are using a Template Condition, a single template can perform the task of comparing both temperatures.
condition:
- condition: template
value_template: >-
{% set test = states("input_number.termometro_test") | int %}
{{ (states("sensor.shelly_h_t_1_temperature") | int) < test or
(states("sensor.shelly_h_t_2_temperature") | int) < test }}
I made some additional tests on another automation I had (didn’t wanted to mess with the currently working one) and there I had no issue in using “below: input_number.termometro_test” directly in the UI.
This however only works when using a “numeric_state” instead of “Device”. If I do this in “Device” I get the following error: “Message malformed: expected float for dictionary value @ data[‘below’]”.
The issue I had of taking 20-30seconds to trigger also disappeared and is now instantly.