Brewing automation with sonoff basic as switch

Hi all,

Thanks to this group I got the following automation rule working:

- id: brewing_temperature
  alias: Brewing temperature
  - platform: state
    entity_id: sensor.brew_temp
    to: Alert
  - service: notify.notify_email
      title: Temperature Alert
      message: "Sensor value outside limits. Currently {{ states.sensor.beer_temp.state\
        \ }}\xB0C"

With this being based on this sensor template:

- platform: template
        "{% if states.sensor.beer_temp.state | int < 20 or states.sensor.beer_temp.state | int > 22 %}
        {% else %}
        {% endif %}"
      friendly_name: "Brew temp"

I have now added a heater, with is controlled by a sonoff basic with tasmota firmware. I have this configured as a switch and it works correctly in a manual or standalone scenario in HA.

To automate it with one of my temperature sensors I created the following automation:

- id: heater_belt_toggle
  alias: Toggle Heater Belt
  - platform: state
    entity_id: sensor.beer_temp
    service_template: >
      {% if | int <= 20 %}
      {% elif | int >= 22 %}
      {% endif %}
    entity_id: switch.heater_belt

Whilst the heater did turn on (at about 19.75 C), it’s now 23.5 C and the heater has not turned off.

Can someone guide me on a way to do this? Simplistically I want the heater on when the beer temp is <=20 C, and turn it off when the temp is >=22 C.

Thanks again…


If you want to keep the temperature between 20 and 22 degrees, why not check out the generic thermostat. It will do exactly what you are looking for. No need to fiddle with automations.

You can set the thermostat to 21 degrees and the tolerance to 1 degree. This will make the thermostat turn on at 19.9 degrees and switch off at 22.1.

Thanks @kirichkov,

I had actually tried that first but it did not seem to work. I’ve reloaded it again and will see how it performs.

Just in case…is it possible to include a value template in this platform? I might need to use the “int” filter for my temperatures to be recognised.


I can confirm the generic thermostat was the correct way to go. Not sure why it didn’t work correctly the first time, but suspect I had set too many parameters for my needs. Part of my config was:

    min_temp: 20 
    max_temp: 22
    target_temp: 21
    tolerance: 0.3

Anyway, all is now correct, and yet again I have learnt something from this group!

1 Like

I’m not sure you can do this directly, however, you can create a template sensor which to use as the temperature sensor, if for some reason you are getting strings, instead of ints. Also keep in mind int is an integer number - so if you’re temperature gives you 22.4 degrees, this will become just 22 as the value of the sensor. It might be more prudent to use the float filter.

Glad I could help!