Help Needed With Thermostat Set temperature and Timer on Sonoff with Tasmota

I want to create the following automation. I’ve tried doing it through automatons, but keep going around in circles. Maybe this is something that needs doing in yaml? Any help appreciated:

Using a Sonoff basic, running Tasmota, with temperature sensor:

  • When button state goes to on, set thermostat to ‘49’, wait for the temperature to be reached, then maintain temperature for 1 hour
  • After the 1 hour, set thermostat to ‘30’ and maintain for 6 hours, then turn off.

Temperature is to be maintained simply by turning the Sonoff output state on/off accordingly. By thermostat, I mean the temperature sensor within the Sonoff controlling the output.

In the automation UI:

Trigger: State
Entity: (sonoff device)
To: On

Action: Call service
Service: climate.set_temperature
entity_id: (your heating device)
temperature: 49

Action: Delay
Time: 01:00:00

Action: Call service
Service: climate.set_temperature
entity_id: (your heating device)
temperature: 30

Action: Delay
Time: 06:00:00

Action: Call service
Service: climate.turn_off
entity: (your heating device)

It might be a better idea to put those actions into a script and call the script, since you can monitor if the script is running and stop it via Lovelace

1 Like

Thanks, but I want the trigger to be the button on the sonoff and the heating device is the relay output from the sonoff.

The device has these attributes:


I see… Hm, I don’t have experience with a vanilla Sonoff device, I flashed Tasmota on mine.
You’d have to disable the function that the button turns on the Heater, then have the button as the trigger.
It either has a short state change or there’s a button_pressed event being triggered which you can listen for, not sure which one is the case here :thinking:

I have Tasmota on mine. Looks like I may have forgot to mention that in the OP… edited now

I think the automation would also have to wait for the temperature to get to 49 before starting the timer.

1 Like

Nice! In that case, you should follow
To get the input via MQTT

To get the wait, add an action before the first delay:

Action: Wait
Wait template: {{ states('YOUR_THERMOSTAT_ENTITY_ID') >= 49 }}
You could add a timeout if you wanted to. See

The thing is, there is no THERMOSTAT_ID, just the temperature sensor on the Sonoff, this is what I’m getting stuck at.

Basically, it’s a Sonoff Basic, running Tasmota, with a temperature sensor connected to it.

The IDs are:


Yeah I meant the sensor.yogurt_thermostat_bme280_temperature
Use that where I’ve put in YOUR_THERMOSTAT_ENTITY_ID
Sorry for the confusion :slight_smile:

Sould work like this:

Action: Wait
Wait template: {{ states('sensor.yogurt_thermostat_bme280_temperature') >= 49 }}

The Sonoff is not set up as a thermostat so Service: climate.set_temperature will not list it.

Ah, I’m sorry, since you used the term “thermostat” I thought you had some other device controlling the heating.
In that case you want it to switch on and off automatically within that timeframe so it keeps the temperature relatively constant?

You should definitely take a look at the Generic Thermostat, 'cause you can basically build your own one inside Home Assistant:
Use your temperature sensor as the target sensor and the Sonoff as the heating switch, take a look at the other parameters as well, like min_cycle_duration

Sorry, I don’t think I made my requirements very clear.

I have just the one device, a Sonoff Basic, running Tasmota, with a temperature sensor attached to it and its relay output. I want to use it as a basic temperature controller…

  • I press the Sonoff button to start the process
  • The Sonoff waits until the temperature reached 49°C and then controls it at that temperature of 1 hours (1°C hysteresis) using the relay output
  • After the one hour, the Sonoff controls the temperature at 30°C for 6 hours (1°C hysteresis). No need for the temperature to get to 30°C before starting the 6 hour timer.

Alright, got it :slight_smile:
As I said, please take a look at the Generic Thermostat: and set it up with your Sonoff.
This will make your life a lot easier, you can call climate.set_temperature then and Home Assistant takes care of switching it on and off :slight_smile:
When you do that, the automation I provided should work.

Ah yes, I have used generic thermostat before, in fact it was the very first thing I set up in Home Assistant, but for some reason it didn’t occur to me to use it in this application. It has an ‘away’ temperature that I should be able to set to the 30°C, so maybe I could turn climate control on by pushing the button, use your automation to wait for the 49°C then set it away after 1 hour.

1 Like

I’ve moved from Tasmota to ESPHome for my complex devices or automations. For example, I’m using it to run my window air conditioners (controlling both fan and compressor). You can use lambdas to create automations that will run on the device itself, without needing to write it in home assistant. The benefit of this is that the device itself will be keeping track of things, and it can run even when disconnected from the wifi.

You can create a project in esphome, use the menu to compile the firmware, then use the tasmota interface to flash the new hardware over the air. It’s really a good solution for projects like these, where the device itself can/should be doing the automated action.

I’m getting there. So far I have got it to set the climate to on and temperature to 49°C when I press the button, but I can’t get the wait template to work.

wait_template: '{{ states(''sensor.yogurt_thermostat_bme280_temperature'') >= 49 }}'
timeout: ''

Results in:

Message malformed: offset should be format ‘HH:MM’ or ‘HH:MM:SS’ for dictionary value @ data[‘action’][2][‘timeout’]


wait_template: "{{ states('sensor.yogurt_thermostat_bme280_temperature') >= 49 }}"

No need for a timeout if you don’t use it

Ok, this is what I’ve ended up with. I’ve not tested it yet though:

  - platform: generic_thermostat #yogurt thermostat
    name: "Yogurt Thermostat"
    heater: switch.yogurt_thermostat
    target_sensor: sensor.yogurt_thermostat_bme280_temperature
    min_temp: 10
    max_temp: 50
    ac_mode: false
    target_temp: 49
    cold_tolerance: 0.2
    hot_tolerance: 0.1
    precision: 0.1
      minutes: 3    
    away_temp: 30 
- id: '1594220900991'
  alias: Yogurt Maker
  description: ''
  - entity_id: binary_sensor.yogurt_thermostat_button1
    platform: state
    to: 'on'
  condition: []
  - data:
      temperature: 49
    entity_id: climate.yogurt_thermostat
    service: climate.set_temperature
  - data: {}
    entity_id: climate.yogurt_thermostat
    service: climate.turn_on
  - wait_template: '{{ states(''sensor.yogurt_thermostat_bme280_temperature'') >=
      49 }}'
  - delay: '1'
  - condition: state
    entity_id: climate.set_preset_mode
    state: away
  - delay: '6'
  - data: {}
    entity_id: climate.yogurt_thermostat
    service: climate.turn_off

Looks good!
A few notes:

  • I don’t know whether or not delay works with just a digit. Try - delay: '01:00' and - delay: '06:00'
  • Make sure the binary_sensor (The button) actually does change states, I have buttons on my smart plugs as well, but they don’t change state when I press them, be sure to check the settings inside Tasmota.
  • As I said earlier, you might want to put all the actions into a script and have the script as an entity in your lovelace UI. You’ll have a visible indication whether or not the script is running and you can stop it.

@fedot, thank you for all your help.

1 Like

Love to help :slight_smile:
Scripts are basically just the “action” part of an automation, in fact if you understand automations, you understand how scripts work as well, they are just a list of actions.