I needed MQTT-adjustable thermostats for all electrical heaters, preferably with power measurement. Couldn't find suitable products on the market so, as usual, had to DIY. As I already had a bunch of Tasmota devices, the choice was obvious.
mem1 - "low" temperature setting when "relay 1" off, normally the minimum temperature allowed in the space
mem2 - "high" temperature setting when "relay 1" on, normally the maximum desired temperature for the space
rule1
ON Tele-DS18B20#temperature DO VAR2 %value% ENDON //Store current temp to var2
ON system#boot DO Var1 %mem1% ENDON //Start with the minimum temperature
ON Tele-DS18B20#temperature<%var1% DO power2 on ENDON //Enable heater, if current temp less than setting
ON Tele-DS18B20#temperature>%var1%+0.5 DO power2 off ENDON //Disable heater, if current temp more than setting + 0.5 degrees
ON power1#state=0 DO backlog Var1 %mem1%;power3 off ENDON //When "relay1" set low, take temp setting from mem1, disable "relay3"
ON power1#state=1 DO backlog Var1 %mem2%;power3 off ENDON //When "relay1" set high, take temp setting from mem2, disable "relay3"
ON power3#state=1 DO backlog Var1 %var2%; power1 off; power2 off ENDON //When "relay3" set high, store current temp as set, disable "relay1" and heater
ON power3#state=0 DO backlog Var1 %mem1%; power1 off ENDON //When "relay3" set low, store mem1 (low) as the setting, power off heater
Without comments for copying:
rule1
ON Tele-DS18B20#temperature DO VAR2 %value% ENDON
ON system#boot DO Var1 %mem1% ENDON
ON Tele-DS18B20#temperature<%var1% DO power2 on ENDON
ON Tele-DS18B20#temperature>%var1%+0.5 DO power2 off ENDON
ON power1#state=0 DO backlog Var1 %mem1%;power3 off ENDON
ON power1#state=1 DO backlog Var1 %mem2%;power3 off ENDON
ON power3#state=1 DO backlog Var1 %var2%; power1 off; power2 off ENDON
ON power3#state=0 DO backlog Var1 %mem1%; power1 off ENDON
rule1 on