Page 1 of 1

Trying to send Sauna temp to Thingspeak

Posted: 08 Sep 2019, 20:14
by jarbeni
Hello!

I have a 18650 battery operated wemos D1 in an enclosure in bathroom and the ds18b20 temp sensor goes to sauna.

I am using analog input along with the temp sensor, for reading battery voltage.

Instead of reading and publishing sauna temperature to Thingspeak in a fixed interval, I would like to make the temperature determine if values are sent in a slow or fast interval.
Because, when sauna is not in use, it is about 25 degrees and something like 15 minute interval is enough.
And then when sauna is turned on to heat up, the temp sensor will soon see a rise in temperature, and after +30 degrees, the interval should change to updating every 1 minute.
After sauna is shut down, and temperature drops below 30 degrees, the update interval should be 15 minutes again.
Also, when ever possible, wemos should be sleeping.


So far, I have no luck.
I´m either locked out of the web interface because of immeadiate sleeping, or things seem to work but no values are sent to ThingsPeak.

This is my latest Rule arrangement:

Code: Select all

on Wifi#Connected do

if [Sauna#Temperature]>30

sendToHTTP api.thingspeak.com,80,/update?key=XXXXXXXXXXXXXXX&field7=[Sauna#Temperature]
timerSet,1,16      //Set Timer 1 for the next event in 16 seconds


on Rules#Timer=1 do  //When Timer1 expires, do
sendToHTTP api.thingspeak.com,80,/update?key=XXXXXXXXXXXXXXX&field8=[akku#percentage]
timerSet,1,0

delay 10000 //lähetetään tietoa 60 sek välein
deepsleep,60 //Sauna is heating, so going for short sleep

endif


if [Sauna#Temperature]<30

sendToHTTP api.thingspeak.com,80,/update?key=XXXXXXXXXXXXXXX&field7=[Sauna#Temperature]
timerSet,2,16      //Set Timer 1 for the next event in 15 seconds
endon

on Rules#Timer=2 do  //When Timer1 expires, do
sendToHTTP api.thingspeak.com,80,/update?key=XXXXXXXXXXXXXXX&field8=[akku#percentage]
timerSet,2,0

delay 20000 //delay just for fun

deepsleep,900 //sauna was cold, going for a longer sleep

endif


endon

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 14:52
by grovkillen
Okay, you're missing the syntax. Please study the documentation regarding how to write rules. EndIf and EndOn for example is really important to get right...


I have created a simpler ruleset for you.

Code: Select all

on Wifi#Connected do
  if [Sauna#Temperature]>30
    event,PublishToThingSpeak=60
  else
    event,PublishToThingSpeak=900
  endif
endon

on PublishToThingSpeak do
  let,1,%eventvalue%
  sendToHTTP,api.thingspeak.com,80,/update?key=XXXXXXXXXXXXXXX&field7=[Sauna#Temperature]
  timerSet,1,15
endon

on Rules#Timer=1 do
  sendToHTTP,api.thingspeak.com,80,/update?key=XXXXXXXXXXXXXXX&field8=[akku#percentage]
  deepsleep,[VAR#1]
endon
Let is setting an internal variable to the preferred deepsleep length (only to be used later once the timer expires). I fetch the internal variable by this syntax [VAR#1].

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 17:56
by jarbeni
You made that look like so much simpler.
I kind of understand what you did there, but I need to look at that more carefully so that I really understand how that is done.

Like you said, endif and endon were something I was unsure how to put them on my code.
That "Let" is completely a new thing for me.

Thanks very much for helping me on this!

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 18:17
by jarbeni
I tried this and it is not sending anything to Thingspeak.

I do see this on serial log:

Code: Select all

6884 : ACT  : sendToHTTP,api.thingspeak.com,80,/update?key=(MY WRITE API KEY)&field7=25.31
6894 : Command: sendtohttp
My earlier attempts failed too, even with the simpliest way to send ANYTHING.

I start to suspect that problem is in the way espeasy sends to Thingspeak using rules.
If I just make a Thingspeak controller and set a device to send values there, it always works.

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 19:07
by TD-er
That's right, there is also an issue about it.
The send to http called from the rules is not waiting for an acknowledgement.

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 21:58
by jarbeni
Yes, I read about that somewhere.

But why my motion detector is working ok then?

It has the collowing code and everything works:

Code: Select all

on Motion#Detection=1 do

SendToHTTP api.thingspeak.com,80,/update?api_key=(MY WRITE API KEY)&field1=0
delay 15000
SendToHTTP api.thingspeak.com,80,/update?api_key=(MY WRITE API KEY)&field1=1
delay 60000
SendToHTTP api.thingspeak.com,80,/update?api_key=(MY WRITE API KEY)&field1=0

delay 60000
endon

Why does this work properly then?
I know I had differences in fimware, so I updated my Sauna Thermometer but that didn´t help.
(That 0, 1, 0, is my way to have a motion indicationg spike that starts from a recent zero value, and not from some previous value in history.)

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 22:24
by TD-er
Oh please do not use delay in rules and especially not delay calls over several seconds.
I really should do something about this delay command, like print it on paper and burn it.

Rules' Delay Statement Considered Harmful.

Please use timers for this and don't use delay.
The delay command does halt the entire node for the set period.

Re: Trying to send Sauna temp to Thingspeak

Posted: 09 Sep 2019, 22:41
by jarbeni
Oh okay then.. :shock:

Re: Trying to send Sauna temp to Thingspeak

Posted: 10 Sep 2019, 10:44
by grovkillen
You could try this one:

Code: Select all

on Motion#Detection=1 do
  if [VAR#16]=0
   Let,16,1
   SendToHTTP,api.thingspeak.com,80,/update?api_key=(MY WRITE API KEY)&field1=0
   TimerSet,1,15
  endif
endon

on Rules#Timer=1 do
  SendToHTTP,api.thingspeak.com,80,/update?api_key=(MY WRITE API KEY)&field1=1
  TimerSet,2,60
endon

on Rules#Timer=2 do
  SendToHTTP,api.thingspeak.com,80,/update?api_key=(MY WRITE API KEY)&field1=0
  TimerSet,3,60
endon

on Rules#Timer=3 do
  Let,16,0
endon


Re: Trying to send Sauna temp to Thingspeak

Posted: 19 Sep 2019, 12:49
by Nestitherapy
I tried and is not sent to Thingspeak.

Re: Trying to send Sauna temp to Thingspeak

Posted: 19 Sep 2019, 13:16
by grovkillen
Can you send it manually? As a test.

Re: Trying to send Sauna temp to Thingspeak

Posted: 19 Sep 2019, 15:26
by TD-er
SendToHTTP and thingspeak are not working, that's a known issue.

For Thingspeak you need to wait for the response from the server and SendToHTTP does not wait for a response.
For that you really need to use the Thingspeak controller.

Re: Trying to send Sauna temp to Thingspeak

Posted: 20 Sep 2019, 12:22
by iron
mine works...

https://thingspeak.com/channels/33034

Code: Select all

On Thermometer#Temperature do
SendToHTTP,api.thingspeak.com,80,/update?api_key={myAPIkey]&field1=[Thermometer#Temperature]&field2=[Thermometer#Humidity]
endon
-D