Good morning.
He is trying to create an automation that must be triggered:
when it’s 6 o’clock
when it is 6 pm and the temperature has been above 30 ° for at least 6 hours.
So something like this:
trigger:
- platform: time
at: "06:00:00"
- and:
- platform: time
at: "18:00:00"
- platform: numeric_state
entity_id: sensor.meteonetwork_temp
above: 30
for: "06:00:00"
condition: []
action:
do somethings
It is known that in the trigger section the options are linked by the default OR operator and it does not manage other logical operators except under platform: template
Then I could modify the trigger, delegating the temperature control to the action section:
Create a trigger-based template binary sensor that goes on when the temperature has been above 30° for six hours, regardless of the clock time, and goes off as soon as the temperature drops below 30° (or some hysteresis value).
Then your automation is triggered by 06:00 and 18:00, with a condition that if it is 18:00, the binary sensor must be on to proceed.
I’m afraid I claimed victory too soon.
Evidently I hadn’t wired my brain yet.
Using the “for” clause causes an error even when used in the condition section
@Troon
Sorry for the delay in responding but… I had to figure out what you meant to me with your advice.
I jotted this down:
- platform: state
binary_sensors:
- trigger:
- platform: numeric_state
entity_id: sensor.meteonetwork_temp
#value_template: "{{ template }}"
above: 30
for: "06:00:00"
oggi_ha_fatto_caldo:
friendly_name: "Oggi ha fatto caldo?"
state: "{{ 'on' if ('trigger.idx', '0') else 'off' }}"
But it keeps giving me error.
Actually once done it would answer my initial question.
If I understand correctly, the “for” option does nothing but every x time (1 sec, 1 minute?) look in the history of the sensor measurements if in the previous 6 hours the temperature has ALWAYS been above 30°
Thinking about it, however, it seems to me a wrong path to follow.
My need is not:
as soon as the temperature exceeds 30° for 6 hours, it activates the alarm
situation in which it would make sense to “listen” permanently on the temperature channel.
My need is:
it’s 6 pm. In the previous 6 hours has the temperature always been above 30°?
I don’t need real-time temperature control.
So it should do the check only once, which it does every X time (1 sec, 1 minute?).
Perhaps there is another more efficient solution.
To resolve independently I had also thought of scheduling the trigger at 18 but this is not feasible due to the impossibility of using the “and” operator.
That’s because I’m using the “modern” configuration format, whereas you seem to be using the legacy format: in the modern format, these template sensors come under template: at the top level, not binary_sensor:. I have mine like this:
Many thanks for your explanations.
I tried to go your way in configuring the configuration.yaml but, for reasons I can’t explain, I fixed the binary.sensor.yaml but got a lot of errors in the sensors.yaml file.
So until I understand what it’s doing I think it’s more convenient (and less OT for this discussion) to continue in the legacy mode.
I managed to create the working binary sensor:
- platform: template
sensors:
oggi_ha_fatto_caldo:
value_template: "{{ states('sensor.meteonetwork_temp')|float(0) >= 10 }}"
friendly_name: "Oggi ha fatto caldo?"
device_class: heat