Turn on/off switch base on temperature reading from termoprobe

Hi all

im trying to make simple altomation but i struggle doing it

i have a termoprobe which reports temperature numbers like 22.10 and simple shelly1 switch

This is the code i manage to piece together ^^

- id: '123123123123'
  alias: turn switch on base on temperature
  description: "turning switch on if temperature is below 30 and turning it off if temperature is over 30"
  trigger:
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
  action:
  - service: >
      {% if states('sensor.1pm_temperature_probe_0') | int <= 26 %} 
        switch.turn_on
      {% elif states('sensor.1pm_temperature_probe_0') | int >= 30 %}
        switch.turn_off
      {% endif %} 
    entity_id: switch.shelly1

All of my reqdings and commands go trough mqtt brocker

Numeric state triggers require either an above or below key (or both)… In this case you would be better off using two Numeric state triggers with ids that can be used to determine the service type used.

Also, your action was missing the target key.

- id: '123123123123'
  alias: turn switch on base on temperature
  description: "turning switch on if temperature is below 26 and turning it off if temperature is over 30"
  trigger:
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
    above: 29.9
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
    below: 26.1
    id: 'on'
  action:
  - service: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.shelly1

Yooo thank you!
This is purfect.

I make a few tests and notice something

I do not know is it HA related or i need to make changes in the code but:
if this code run, and turn on the the switch when temperature is below 26, and i manually turn off the switch, it does not turn on again when the new reading of 24( for example) comes again. So now the temperature is under 26 but the switch does not switch on till i make temperature go over 26 and go back down below 26.

Is it there a way for automation to check every cycle and make it turn on the switch again when readings are below 24 even if i turn it off before last cycle reading?

That is the expected behavior. A Numeric state trigger only fires when the numeric value of an entity’s state crosses a given threshold. Once fired, the trigger will not fire again until it is reset by crosses the threshold in the opposite direction.

If you need to, it is much more efficient to add one or more fallback triggers with the same id. than to use continuous polling.

alias: turn switch on base on temperature
  description: "turning switch on if temperature is below 26 and turning it off if temperature is over 30"
  trigger:
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
    above: 29.9
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
    below: 26.1
    id: 'on'
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
    above: 31
    id: 'off'
  - platform: numeric_state
    entity_id: sensor.1pm_temperature_probe_0
    below: 24
    id: 'on'
  action:
  - service: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.shelly1

It is possible to check the value of the sensor on a regular polling cycle using the Time Patter trigger. This is not the recommended method to use because it is inefficient. To use that method you would need to redesign the automation significantly.

This did not work :confused:
May be it can be suggested as a feature. Im sure that i am not the only one with that kind of a case :smiley:

I will try some stuff and i will post them if i found somethin.

In a meantime if someone has an a idea please share :slight_smile:

Why not just use a generic thermostat?
That will solve all your issues.

1 Like

Do you have some specific devices in mind ( i mean brand and model ) ?
They should support mqtt.

And what is the difference between them and termoprobe ?

It’s not a device. Its more like a integrated automation just like you wanted.

Generic Thermostat - Home Assistant (home-assistant.io)

Good suggestion but it does not fit my case :confused:
i cannot set a range between 2 points of temperature
also i used the code from Generic Thermostat - Home Assistant and it did not turn on my device after i set comf.temp. to be 30.

Sure you can…
If the range is 26 to 30 then set it to 28 with 2 degree hot and cold tolerance.

? Ok… It works for everyone else. Without seeing what you did we cant help you.

Make sure you address the use case of the thermo probe going offline. As otherwise the heat may remain on for a long time when that sensor fails or the comms to the sensor goes down.