Help with rules

Moderators: grovkillen, Stuntteam, TD-er

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

Help with rules

#1 Post by Sasch600xt » 22 Nov 2019, 18:12

Hello all,

i want to send an MQTT message to an ESP (works already)
and if i send once a "1" or "true" i want to publish a sensor value every 10 seconds.

if i send once a "0" or "false" i want to disable the timer or if thats not possible set it t a long period.

This is my start so far:

Code: Select all

on MQTT_INPUT#TimerAmpere=1 do
 timerSet,1,10
endon

on MQTT_INPUT#TimerAmpere=0 do
 timerSet,1,0
endon

On Rules#Timer=1 do
publish,"%sysname%/status/Ip_Adresse","%ip%"
// here i should retrigger the timer depents on TimerAmpere is 1 or 0 i guess ?
endon
Can someone help ?
Would be awesome :)

Have a great day
Last edited by Sasch600xt on 22 Nov 2019, 19:08, edited 1 time in total.
"the flat earth society has members all around the globe"

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

Re: Help with rules

#2 Post by TD-er » 22 Nov 2019, 18:31

Why not use variables to store the state?
Then you can set that value to 0 or 1 depending on the MQTT messages.
In the timer call, you just check for the value of the variable and only then do your stuff.

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

Re: Help with rules

#3 Post by Sasch600xt » 22 Nov 2019, 18:34

sounds great,

do you have an little example ?

i am right now not sure about the syntax.

are you talking about this for example: %v1% ?
"the flat earth society has members all around the globe"

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

Re: Help with rules

#4 Post by TD-er » 22 Nov 2019, 19:18

Sasch600xt wrote:
22 Nov 2019, 18:34
i am right now not sure about the syntax.
Well, neither am I, that's when I ask Jimmy for the rules :)

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

Re: Help with rules

#5 Post by Sasch600xt » 22 Nov 2019, 19:25

i found a snippet at the forum, but it is not working right now.

The variable changes from 0 to 1 by sending a MQTT message, so this works.

But the part with publish will not work..

Do you see the problem ?

Code: Select all

on MQTT_INPUT#TimerAmpere=1 do
 let,1,1
endon

on MQTT_INPUT#TimerAmpere=0 do
 let,1,0
endon

On Rules#Timer=1 do
if %v1%=1
publish,"%sysname%/status/Uptime",%uptime%
endif
endon
"the flat earth society has members all around the globe"

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

Re: Help with rules

#6 Post by Sasch600xt » 22 Nov 2019, 19:36

ok....as usally...my fault.

i forgot to set the timer again....

so this works now like expected :

Code: Select all

on MQTT_INPUT#TimerAmpere=1 do
 let,1,1
endon

on MQTT_INPUT#TimerAmpere=0 do
 let,1,0
endon

On Rules#Timer=1 do
if %v1%=1
publish,"%sysname%/status/Uptime",%uptime%
endif
timerSet,1,10
endon
"the flat earth society has members all around the globe"

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

Re: Help with rules

#7 Post by TD-er » 22 Nov 2019, 19:47

Looks good :)

Code: Select all

on MQTT_INPUT#TimerAmpere=1 do
 let,1,1
endon

on MQTT_INPUT#TimerAmpere=0 do
 let,1,0
endon
I think (hope) it could be made shorter (although not completely the same as it allows other values too):

Code: Select all

on MQTT_INPUT#TimerAmpere do
 let,1,[MQTT_INPUT#TimerAmpere]
endon

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

Re: Help with rules

#8 Post by Sasch600xt » 22 Nov 2019, 19:52

Code: Select all

on MQTT_INPUT#TimerAmpere do
 let,1,[MQTT_INPUT#TimerAmpere]
endon
works perfect :)
"the flat earth society has members all around the globe"

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests