Moderators: grovkillen, Stuntteam, TD-er
-
Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
#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: 8754
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
Contact:
#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.
-
Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
#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: 8754
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
Contact:
#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
-
Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
#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"
-
Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
#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: 8754
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
Contact:
#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
-
Sasch600xt
- Normal user
- Posts: 164
- Joined: 10 Sep 2018, 16:37
#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"
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 105 guests