Simple Thermostat Example not working with DS18B20

91 views
Skip to first unread message

Fibra

unread,
Jun 3, 2022, 8:04:06 AM6/3/22
to TasmotaUsers
Hello everybody,

I`ve bean having hard time with example from this page: https://tasmota.github.io/docs/Rules/#watchdog-for-wi-fi-router

I have tried several installations and pin configurations, both on the Wemos Mini and ESP32, each with coresponding firmware.

On my last attempt with Wemos Mini, I have configured as follows

  GPIO 0: Relay 1
  GPIO 2: DS18B20
  GPIO 14: Switch 1

I have issued all these config commands:

  SwitchMode1 3 <- Use the switch1 as pushbutton (It will allow us to disable the link between the button and the relay by inserting a rule to dictate what the pushbutton will do - NOTE: Until rules are created the pushbutton will still control the relay!)
  Rule1 1 <- turn on rules
  Rule1 4 <- turn off one-shot rule
  TelePeriod 60 <- check temp every minute
  SetOption26 1 <- use Power1 on mqtt messages
  SetOption0 0 <- dont save relay status on eeprom
  PowerOnState 0 <- start all relays off
  Mem1 0 <- thermostat status: 0-off 1-enabled - View or set by MQTT cmnd/mqttTopic/mem1
  Mem2 25 <- setpoint Temp upper limit - View or set by MQTT cmnd/mqttTopic/mem2
  Mem3 23 <- setpoint Temp lower limit - View or set by MQTT cmnd/mqttTopic/mem3
  Var1 0 <- thermostat actual status: 1-OK 0-NOT READY - View by MQTT cmnd/mqttTopic/var1

followed by these commands:

Rule1
  ON system#boot DO RuleTimer1 70 ENDON
  ON Switch1#State DO event toggling1=%mem1% ENDON
  ON event#toggling1=0 DO mem1 1 ENDON
  ON event#toggling1=1 DO mem1 0 ENDON
  ON Rules#Timer=1 DO Backlog var1 0; RuleTimer1 70; Power1 0 ENDON
 
originally it is designed to be used with SI7021

  ON tele-SI7021#temperature DO Backlog var1 1; RuleTimer1 70; event

so, I have changed it to:
 
  ON tele-DS18B20#temperature DO Backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% ENDON
 
the rest of the code is left unchanged

  ON event#ctrl_ready>%mem1% DO var1 0 ENDON
  ON event#temp_demand>%mem2% DO Power1 0 ENDON
  ON event#temp_demand<%mem3% DO Power1 %var1% ENDON

When I test the example from the page without the sensor, it works as it is designed:
It activates Relay (LED in my case) on the GPIO 0 when I issue command: event temp=26
deactivates Relay when I issue command: event temp=20
deactivates Relay if I wait more than 1 minute
reactivates the rule if I issue again event temp=20

So, I am not sure why does it not work with this line:

  ON tele-DS18B20#temperature DO Backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% ENDON

Here is the log:

12:55:14.615 RUL: EVENT#TOGGLING1=0 performs "mem1 1"
12:55:14.623 MQT: stat/tasmota_E225F8/RESULT = {"Mem1":"1"}
12:55:21.882 CMD: var1
12:55:21.890 MQT: stat/tasmota_E225F8/RESULT = {"Var1":"0"}
12:55:32.373 MQT: tele/tasmota_E225F8/STATE = {"Time":"2022-06-03T12:55:32","Uptime":"0T00:37:10","UptimeSec":2230,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":21,"MqttCount":1,"POWER1":"OFF","Wifi":{"AP":1,"SSId":"Assus_2G","BSSId":"FC:34:97:06:44:38","Channel":4,"Mode":"11n","RSSI":100,"Signal":-38,"LinkCount":1,"Downtime":"0T00:00:04"}}
12:55:32.386 MQT: tele/tasmota_E225F8/SENSOR = {"Time":"2022-06-03T12:55:32","Switch1":"ON","DS18B20":{"Id":"01201C82DD6E","Temperature":26.2},"TempUnit":"C"}
12:56:19.385 RUL: RULES#TIMER=1 performs "Backlog var1 0; RuleTimer1 70; Power1 0"
12:56:19.422 MQT: stat/tasmota_E225F8/RESULT = {"Var1":"0"}
12:56:19.624 MQT: stat/tasmota_E225F8/RESULT = {"T1":70,"T2":0,"T3":0,"T4":0,"T5":0,"T6":0,"T7":0,"T8":0}
12:56:19.871 MQT: stat/tasmota_E225F8/RESULT = {"POWER1":"OFF"}
12:56:19.876 MQT: stat/tasmota_E225F8/POWER1 = OFF

Despite

12:58:26.135 CMD: mem1
12:58:26.142 MQT: stat/tasmota_E225F8/RESULT = {"Mem1":"1"}
12:58:32.372 MQT: tele/tasmota_E225F8/STATE = {"Time":"2022-06-03T12:58:32","Uptime":"0T00:40:10","UptimeSec":2410,"Heap":26,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"OFF","Wifi":{"AP":1,"SSId":"Assus_2G","BSSId":"FC:34:97:06:44:38","Channel":4,"Mode":"11n","RSSI":100,"Signal":-39,"LinkCount":1,"Downtime":"0T00:00:04"}}
12:58:32.390 MQT: tele/tasmota_E225F8/SENSOR = {"Time":"2022-06-03T12:58:32","Switch1":"ON","DS18B20":{"Id":"01201C82DD6E","Temperature":26.4},"TempUnit":"C"}

I have this:

12:58:35.554 MQT: stat/tasmota_E225F8/RESULT = {"Var1":"0"}

Sorry if I`ve included so much data, I have thought it would be helpfull to know what exactly I did.
Thanks in advance for the help.

Sasha

Philip Knowles

unread,
Jun 3, 2022, 8:42:54 AM6/3/22
to Fibra, TasmotaUsers

I’m not saying this I the issue but GPIO2 is possibly not a good choice for the DS18B20. It’s connected to the onboard LED and pulled high at boot. Almost any other pin would be better (other than GPIO16). This page is a useful resource

 

ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

 

The rules are slightly different from the original

Rule ON tele-SI7021#temperature DO Backlog var1 1; RuleTimer1 30; event ctrl_ready=1; event temp_demand=%value% ENDON

 

ON tele-DS18B20#temperature DO Backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% ENDON

So you are not “resetting the checking timer”

 

Not sure if that’s the issue but it seems to be important

 

Regards

 

Phil K

Sent from Mail for Windows

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/d8a6bf23-22d4-41a4-9ba1-3a7c893c2b93n%40googlegroups.com.

 

Philip Knowles

unread,
Jun 3, 2022, 8:48:57 AM6/3/22
to Fibra, TasmotaUsers

BTW the explanation of the rule and the code have different values for the Timer1 (70 and 30) and I don’t know which should be the correct value.

 

Sent from Mail for Windows

 

From: Fibra
Sent: 03 June 2022 13:04
To: TasmotaUsers
Subject: Simple Thermostat Example not working with DS18B20

 

Hello everybody,

--

Fibra

unread,
Jun 3, 2022, 10:39:02 AM6/3/22
to TasmotaUsers
Thanks mate. 
I have tried with both values (70 and 30) and it seams there are no difference. Not sure where should I swap 70 for 30. I did this:
 
Rule1
ON system#boot DO RuleTimer1 70 ENDON
ON switch1#state DO Backlog event toggling1=%mem1% ENDON

ON event#toggling1=0 DO mem1 1 ENDON
ON event#toggling1=1 DO mem1 0 ENDON
ON Rules#Timer=1 DO Backlog var1 0; RuleTimer1 70; Power1 0 ENDON
ON tele-DS18B20#temperature DO Backlog var1 1; RuleTimer1 30; event ctrl_ready=1; event temp_demand=%value% ENDON

ON event#ctrl_ready>%mem1% DO var1 0 ENDON
ON event#temp_demand>%mem2% DO Power1 0 ENDON
ON event#temp_demand<%mem3% DO Power1 %var1% ENDON


Beside config comands, this is what I have pasted. What bothers me is capital letters. I have read it it not case sensitive, but I know nothing about coding.

Philip Knowles

unread,
Jun 3, 2022, 2:27:49 PM6/3/22
to Fibra, TasmotaUsers

Right, I’ve had a chance to read the code. RuleTimer1 needs to be higher than TelePeriod so it should be 70 in all cases – if we can get it working I will get the code error fixed.

 

Just to be absolutely sure can you cut and paste each line into console one line at a time

 

Rule1 ON system#boot DO RuleTimer1 70 ENDON

Rule1 + ON switch1#state DO Backlog event toggling1=%mem1% ENDON

Rule1 + ON event#toggling1=0 DO mem1 1 ENDON

Rule1 + ON event#toggling1=1 DO mem1 0 ENDON

Rule1 + ON Rules#Timer=1 DO Backlog var1 0; RuleTimer1 70; Power1 0 ENDON

Rule1 + ON tele-DS18B20#temperature DO Backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% ENDON

Rule1 + ON event#ctrl_ready>%mem1% DO var1 0 ENDON

Rule1 + ON event#temp_demand>%mem2% DO Power1 0 ENDON

Rule1 + ON event#temp_demand<%mem3% DO Power1 %var1% ENDON

Backlog SwitchMode1 3; Rule1 1; Rule1 4; TelePeriod 60; SetOption26 1; SetOption0 0; poweronstate 0; mem1 0; mem2 25; mem3 23; var1 0

 

The key line is

ON tele-DS18B20#temperature DO Backlog var1 1; RuleTimer1 70; event ctrl_ready=1; event temp_demand=%value% ENDON

Which does the following

Sets var1 to 1 (which will be used to turn the power on later if needed)

Restarts the RuleTimer (for 70 seconds)

Run the ctrl_ready event (this checks whether the thermostat is enabled if not sets var1 to 0)

Runs temp_demand event (if the temperature is greater than the high point switches power off – if lower than low point uses var1 to decide if power should be on or not)  

 

However, in the console output you show only the line above runs

ON Rules#Timer=1 DO Backlog var1 0; RuleTimer1 70; Power1 0 ENDON

 

If it doesn’t work after re-entering the code try this

Rule2 on ds18b20#temperature<30 do power1 1 endon

Rule2 1

Which will simply check that the ds18b20 is being read and turn the power on if the temperature is lower than 30

 

Good luck

 

Phil K

Fibra

unread,
Jun 4, 2022, 2:39:47 AM6/4/22
to TasmotaUsers
Wow. It works now after entering it line by line. Thanks a lot, Phil! You are a saver. I've been batling this for 2 whole days.
So, not sure what was the problem now. Can't I batch whole rule at once? Or can I use ";" to separate the lines?
I have basis now to expand thos. I am building an automation to off-gass a room which emit a lot of VOC because it is made out of the epoxy or polyester. I need to heat it to about 35°C for a couple of hours, and than vent an air out or a couple of hours. I can program the timers for whole day to do that.

Philip Knowles

unread,
Jun 4, 2022, 3:26:19 AM6/4/22
to Fibra, TasmotaUsers
At least it working. The Rule1 +  is easiest way to enter a long rule 1 line at a time.



From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Fibra <sasa...@gmail.com>
Sent: Saturday, June 4, 2022 7:39:46 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages