Syntax

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
Sasch600xt
Normal user
Posts: 164
Joined: 10 Sep 2018, 16:37

Syntax

#1 Post by Sasch600xt » 30 Mar 2020, 18:00

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 !
"the flat earth society has members all around the globe"

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Syntax

#2 Post by TD-er » 30 Mar 2020, 18:44

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?

User avatar
Sasch600xt
Normal user
Posts: 164
Joined: 10 Sep 2018, 16:37

Re: Syntax

#3 Post by Sasch600xt » 30 Mar 2020, 18:57

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 :)
"the flat earth society has members all around the globe"

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Syntax

#4 Post by grovkillen » 30 Mar 2020, 20:44

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
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
Sasch600xt
Normal user
Posts: 164
Joined: 10 Sep 2018, 16:37

Re: Syntax

#5 Post by Sasch600xt » 30 Mar 2020, 21:09

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)
"the flat earth society has members all around the globe"

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Syntax

#6 Post by grovkillen » 30 Mar 2020, 22:22

Ok then your first suggestion work. If you need that buffer.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Syntax

#7 Post by TD-er » 30 Mar 2020, 22:42

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests