Automate turn on switch if the temperature under 33

hey,

i want to do automation if the sensor under 33
its turn on automaticly at 6pm o’clock

its look like this but dont work for me.

 - id: boiler_on
   alias: boiler on
   trigger:
     - platform: numeric_state
       entity_id: sensor.boiler_temp_sonoff
       below: 33
   condition:
     condition: and
     conditions:
       - condition: time
         after: '18:00:00'
         before: '22:00:00'
   action:
     - service: notify.ggg
       data:
         message: "boiler turn on"
     - service: homeassistant.turn_on
       entity_id: switch.airwick_parantes_toilet

please help
thanks

According to the documentation, the numeric state trigger

Fires when the numeric value of an entity’s state (or attribute’s value if using the attribute property, or the calculated value if using the value_template property) crosses (and only when crossing) a given threshold. On state change of a specified entity, attempts to parse the state as a number and fires if the value is changing from above to below or from below to above the given threshold.

So, your automation will only trigger if sensor.boiler_temp_sonoff goes from above 33 to below 33 between 18:00 and 22:00.

so what i need to do?
what is the best configuration for me?

This ensures the switch is turned on whenever the boiler temperature is below the threshold and within the desired time range.

 - id: boiler_on
   alias: boiler on
   trigger:
     - platform: numeric_state
       entity_id: sensor.boiler_temp_sonoff
       below: 33
     - platform: time
       at: '18:01:00'
   condition:
     - condition: time
       after: '18:00:00'
       before: '22:00:00'
     - condition: numeric_state
       entity_id: sensor.boiler_temp_sonoff
       below: 33
   action:
     - service: notify.ggg
       data:
         message: "boiler turn on"
     - service: homeassistant.turn_on
       entity_id: switch.airwick_parantes_toilet

this code dont work

Do you want the boiler to turn on only at 6pm if its below 33
or
do you want the boiler to turn on if temp is below 33 at any time between 6pm & 10pm?

I am a little confused as your question does not appear to match your posted automation.

its work only if now the temperature above 33 and down to 32
but now the temprature is 23
and dont work

yes
i want the boiler to turn on if temp is below 33 at any time between 6pm & 10pm

Thats correct as the trigger of below 33 will only EVER trigger when the state transitions from ABOVE 33 to BELOW 33.

So it can go up and down all it likes all the time it stays below 33 it wont trigger and all the time it stays above 33 it wont trigger either

but what time is it where you are?

the automation assumes some initial conditions for it to trigger:

That the state is above 33 and that the time is before 1801.

If those initial conditions aren’t met (say it’s now before 1801 but below 33) then the automation won’t trigger until those conditions change to cross the threshold of the triggers (in this case it becomes later than 1801).

Is there a way to make it work?
Because that’s exactly the situation

Is there a way to make it work?
Because that’s exactly the situation

The code @123 posted will trigger the automation if the sensor drops below 33 at anytime of the day or night - BUT the condition will ensure the automation only does anything if the time is between 6pm and 10pm. The automation will also trigger at 6:01pm and the condition will check if the sensor is below 33.
There is no problem with that code, please post the automation trace if you believe it is not working.

I think there may be some confusion here as what @123 posted would work but as explained if the time is already passed 18:01 hours and the temp is already below 33 then it will not trigger.

Have you tried what was suggested by 123 and used the developer tools to set the state of the temp entity to something above 33 then either let it update or wait a few seconds and then set it to any value below 33 to check if 123’s automation actually works?

i check and its work but with problem beacuse the temp now is 23
and not above 33

This is a really important point that should not be overlooked for any thermostat-type automation.

I recall a GitHub issue describing the same thing for a users beer cooler. Basically this is expected behaviour and we need to consider a ‘missed trigger’ scenario when writing automations.

I have changed all my thermostat-type automations to trigger at every temperature change and no longer use numeric state as the trigger.

The temperature check then goes in the condition.

This solves the trigger state change from being missed at the expense of added log volume.

You can either wait till it is after 1801 when the automation should trigger on its own or if you really want the heater to turn on right now then just turn on the heater switch manually via it’s entity.

but also be aware that the automation as written will only ever turn on the switch. it will never turn it off.

if you want the heater to turn off at certain triggers/conditions automatically then you will need another automation or modify the existing one to do that.

You can share the code please?

Sure thing. We take the code from @123 and make one change. The trigger changes from numeric_state to just plain’ol state with no attributes, values, etc. We can also remove the time trigger as that is no longer needed as it is already in conditions.

I have one of the Sonoff temp/humidity sensors. They appear to update every five minutes or so. Therefore expect for this automation to trigger every five minutes to evaluate if the boiler needs to turn on.

PS. This same automation can also be used to turn off the boiler if you used a choose action and individual temperature conditions.

 - id: boiler_on
   alias: boiler on
   trigger:
     - platform: state
       entity_id: sensor.boiler_temp_sonoff
   condition:
     - condition: time
       after: '18:00:00'
       before: '22:00:00'
     - condition: numeric_state
       entity_id: sensor.boiler_temp_sonoff
       below: 33
   action:
     - service: notify.ggg
       data:
         message: "boiler turn on"
     - service: homeassistant.turn_on
       entity_id: switch.airwick_parantes_toilet
3 Likes

work perfect!
thanks
@ crlogic
@ 123