Page 1 of 1

Syntax

Posted: 30 Mar 2020, 18:00
by Sasch600xt
Hello,

i am not sure about the Syntax (again :()
i do not have the device at home, so i have to make sure the code is working when i upload it to the device which controls some big gas heaters.
What i try to do is an emergency plan when my houscontrolling software crashes.
So in the case MQTT is disconnected i want the heaters to switch on and off between 15-16 degree untill MQTT Broker is online again.

Is this the right code ? Or would you guys change it ?

Code: Select all

on MQTT#Connected do
timerSet,8,0
endon

on MQTT#Disconnected do
timerSet,8,60
endon


On Rules#Timer=8 do
if [Unten#Temp]<15
mcpgpio,1,1
if [Unten#Temp]>16
mcpgpio,1,0
timerSet,8,60
endon
Thank you so much for your help !

Re: Syntax

Posted: 30 Mar 2020, 18:44
by TD-er
The timer will not be restarted when the temp is 15 .. 16 degree.
I would not use an timer for this but just run it on every minute.

Also, what is the state if the ESP is not powered?

Re: Syntax

Posted: 30 Mar 2020, 18:57
by Sasch600xt
but it should run once in a minute while MQTT Broker is offline.

after MQTT broker is online it should not run at all.

So the timer set was wrong ?

is this better ?

Code: Select all

on MQTT#Connected do
timerSet,8,0
endon

on MQTT#Disconnected do
timerSet,8,60
endon


On Rules#Timer=8 do
timerSet,8,60
if [Unten#Temp]<15
mcpgpio,1,1
endif
if [Unten#Temp]>16
mcpgpio,1,0
endif
endon
So with this code will it switch the IO to 1 under 15 degree and to 0 above 16 degree only while MQTT is disconnected ?
This would be the goal :)

Re: Syntax

Posted: 30 Mar 2020, 20:44
by grovkillen
Try this instead:

Code: Select all

on MQTT#Connected do
timerSet,8,0
endon

on MQTT#Disconnected do
timerSet,8,60
endon


On Rules#Timer=8 do
timerSet,8,60
 if [Unten#Temp]<15
  mcpgpio,1,1
 else
  mcpgpio,1,0
 endif
endon

Re: Syntax

Posted: 30 Mar 2020, 21:09
by Sasch600xt
thank you but this would trigger the heaters too often.

temp is an float with 2 decimals.

so with your code the heater would switch on at 14.99 degree and switch off at 15.00, am i right ?


i need one degree buffer (<15 ON and >16 Off)

Re: Syntax

Posted: 30 Mar 2020, 22:22
by grovkillen
Ok then your first suggestion work. If you need that buffer.

Re: Syntax

Posted: 30 Mar 2020, 22:42
by TD-er
Using timer is OK, but I would suggest to store the state of the MQTT in a variable.
So on an event for connected/disconnected you can set this variable to 0 or 1 and periodically you just check this variable.
This makes the code much more simple.

And if you just test it every minute, there is no harm in running it on the clock time event. This way you can't forget to enable it again.