Publishing GPIO state via MQTT on bootup and timer
Moderators: grovkillen, Stuntteam, TD-er
Publishing GPIO state via MQTT on bootup and timer
Good day
I need to publish the state of a GPIO pin after boot and via a timer (each 30s). I am using openhab 1.8 on a raspberry pi 2 and I get the status back when a event occurs (command send from openhab to change state via mqtt) but needs it to be updated without waiting for an event.
I uploaded the latest addition of build 101 from github.
How can I add a timer and trigger the publishing of the GPIO state when the timer runs out. Is it easier to add an additional plugin at the devices tab, almost similar the the "input switch".
Any ideas, I am new to this...
I need to publish the state of a GPIO pin after boot and via a timer (each 30s). I am using openhab 1.8 on a raspberry pi 2 and I get the status back when a event occurs (command send from openhab to change state via mqtt) but needs it to be updated without waiting for an event.
I uploaded the latest addition of build 101 from github.
How can I add a timer and trigger the publishing of the GPIO state when the timer runs out. Is it easier to add an additional plugin at the devices tab, almost similar the the "input switch".
Any ideas, I am new to this...
Re: Publishing GPIO state via MQTT on bootup and timer
May you use the rules Option?
Here in the forum are examples for usage...
Here in the forum are examples for usage...
Re: Publishing GPIO state via MQTT on bootup and timer
Ah...thank you, I will try it and give feedback. I was not aware of Rules, I used to work with release 78.
-
- Normal user
- Posts: 25
- Joined: 19 Apr 2016, 11:12
Re: Publishing GPIO state via MQTT on bootup and timer
Hi.
Can you give me a sample rule which publishes the switch status or gpio status every 5 minutes?
I can't seem to get it work and there's no documentation on the 'publish' option in the rules section.
Many thanks, Andy.
Can you give me a sample rule which publishes the switch status or gpio status every 5 minutes?
I can't seem to get it work and there's no documentation on the 'publish' option in the rules section.
Many thanks, Andy.
Re: Publishing GPIO state via MQTT on bootup and timer
I have not spent a lot of time on this. The timer is easy to set up to execute an event. But I do not know how to publish the gpio state via MQTT from the rules.
Can anyone assist?
Thanks
Can anyone assist?
Thanks
Re: Publishing GPIO state via MQTT on bootup and timer
it should be possible to publish someting. It is first implemented in R100, but I do not have the experience myself.
This is the description: 'Publish <topic>,<value>' command to send remote commands to other ESP using MQTT broker
Hereunder an example with:
'SendTo <unit>,<command>' command for remote unit control commands (uses the internal peer to peer UDP messaging)
on demoEvent do
sendTo 2,event,givemesomewater (to use the previous example.
endo
or
on demoEvent do
sendTo 2,GPIO,2,1
endon
This is the description: 'Publish <topic>,<value>' command to send remote commands to other ESP using MQTT broker
Hereunder an example with:
'SendTo <unit>,<command>' command for remote unit control commands (uses the internal peer to peer UDP messaging)
on demoEvent do
sendTo 2,event,givemesomewater (to use the previous example.
endo
or
on demoEvent do
sendTo 2,GPIO,2,1
endon
Re: Publishing GPIO state via MQTT on bootup and timer
its shortly mentioned in the wiki:
http://www.esp8266.nu/index.php/Tutorial_Rules
and it would be straighter, to have all do-actions separated homogenoiusly with comma...
like the wiki http://www.esp8266.nu/index.php/Tutorial_Rules says for:
and misleading here:
it would be more logical to have this comma also with
and
--------edit:
and the wiki is missing this option "inputswitchstate" used here http://www.esp8266.nu/forum/viewtopic.p ... tate#p6519
http://www.esp8266.nu/index.php/Tutorial_Rules
and it would be straighter, to have all do-actions separated homogenoiusly with comma...
like the wiki http://www.esp8266.nu/index.php/Tutorial_Rules says for:
Code: Select all
gpio,2,0 // close valve
Code: Select all
timerSet,1,30 //Set Timer1 for the next event in 30 seconds
timerSet 1,600 // 10 minute timer
Code: Select all
sendTo 2,event,givemesomewater (to use the previous example.
Code: Select all
Publish <topic>,<value>
and the wiki is missing this option "inputswitchstate" used here http://www.esp8266.nu/forum/viewtopic.p ... tate#p6519
Code: Select all
on switchon do
gpio 12,1
gpio 13,0
inputswitchstate 0,1
endon
on switchoff do
gpio 12,0
gpio 13,1
inputswitchstate 0,0
endon
Last edited by tozett on 10 May 2016, 08:03, edited 2 times in total.
Re: Publishing GPIO state via MQTT on bootup and timer
Thank you for the assistance, my rules are working - publishing mqtt:
on boot up I have i need to switch on gpio 12:
on System#Boot do
publish /Light_Living/gpio/12,1
endon
and for a push button I added a switch in the devices tab:
on Switch#Switch=1 do
publish /Light_Living/gpio/12,1
endon
on Switch#Switch=0 do
publish /Light_Living/gpio/12,0
endon
on boot up I have i need to switch on gpio 12:
on System#Boot do
publish /Light_Living/gpio/12,1
endon
and for a push button I added a switch in the devices tab:
on Switch#Switch=1 do
publish /Light_Living/gpio/12,1
endon
on Switch#Switch=0 do
publish /Light_Living/gpio/12,0
endon
Re: Publishing GPIO state via MQTT on bootup and timer
Problem is when both esp and broker (and wifi) dead,trokkie wrote:Thank you for the assistance, my rules are working - publishing mqtt:
on boot up I have i need to switch on gpio 12:
on System#Boot do
publish /Light_Living/gpio/12,1
endon
esp boots faster than the broker, so the rule won't work
-
- Normal user
- Posts: 25
- Joined: 19 Apr 2016, 11:12
Re: Publishing GPIO state via MQTT on bootup and timer
Hi. I'm using v105 and there is the Boot State option on each Device and there is also a DELAY setting which is really a 'number of seconds between publishing the state of the device'
Change it from zero to 60 and your device state will be automatically sent to the MQTT broker every minute. I use it to initialise all my switches (lights) in OpenHAB.
One thing to be careful of (I got caught out with the Sonoff hardware) if you set a rule to use the local button to switch on/off the relay. Do not set the delay time on this switch as you will find the light switches on then off every minute. Scared the wife when it kept happening
Change it from zero to 60 and your device state will be automatically sent to the MQTT broker every minute. I use it to initialise all my switches (lights) in OpenHAB.
One thing to be careful of (I got caught out with the Sonoff hardware) if you set a rule to use the local button to switch on/off the relay. Do not set the delay time on this switch as you will find the light switches on then off every minute. Scared the wife when it kept happening
Re: Publishing GPIO state via MQTT on bootup and timer
hi,
i am using r106 and tried to publish MQTT in my rules,
but i show only in the log, but my node-red does not receives the message from the rules.
other messages are received normaly.
any hints to debug? who has "publish" with mqtt in the rules working?
i am using r106 and tried to publish MQTT in my rules,
but i show only in the log, but my node-red does not receives the message from the rules.
other messages are received normaly.
any hints to debug? who has "publish" with mqtt in the rules working?
- Attachments
-
- Zwischenablage01-publish.png (129.82 KiB) Viewed 20055 times
Re: Publishing GPIO state via MQTT on bootup and timer
at the moment i think, the "Publish" command in the rules-section (or also serial?)
does nothing in r106. is it a bug? i subscribed to the whole topic, every other topics are published normally...
what can i check?
additional question: does the rules-"publish" depends somehow on the main-mqtt config?
hmmm, but the main-mqtt config is working succesfull....
the log shows no MQTT action after the execution of the rule.
is there logging missing? or mqtt execution missing? hmmm
does nothing in r106. is it a bug? i subscribed to the whole topic, every other topics are published normally...
what can i check?
additional question: does the rules-"publish" depends somehow on the main-mqtt config?
hmmm, but the main-mqtt config is working succesfull....
the log shows no MQTT action after the execution of the rule.
is there logging missing? or mqtt execution missing? hmmm
- Attachments
-
- Zwischenablage02-publish.png (47.1 KiB) Viewed 20055 times
Re: Publishing GPIO state via MQTT on bootup and timer
The default Subscribe template is /%sysname%/#
So, try Publish /ESP/03/...
So, try Publish /ESP/03/...
Re: Publishing GPIO state via MQTT on bootup and timer
i will give it a try,
but i thought i can publish any (new/own) topic,
like i do with a mqtt-client ...
can't i?
but i thought i can publish any (new/own) topic,
like i do with a mqtt-client ...
can't i?
Re: Publishing GPIO state via MQTT on bootup and timer
My rules also stopped working in R105 already. Watching this subject for some advise as well.
---------------------------------------------
on Clock#Time=all,20:15 do
GeyserOn
endon
on Clock#Time=all,22:45 do
GeyserOff
endon
on GeyserOn do
GPIO,16,1
Publish /RHZA/ESP03/GPIO/16,1
endon
on GeyserOff do
GPIO,16,0
Publish /RHZA/ESP03/GPIO/16,0
endon
---------------------------------------------
---------------------------------------------
on Clock#Time=all,20:15 do
GeyserOn
endon
on Clock#Time=all,22:45 do
GeyserOff
endon
on GeyserOn do
GPIO,16,1
Publish /RHZA/ESP03/GPIO/16,1
endon
on GeyserOff do
GPIO,16,0
Publish /RHZA/ESP03/GPIO/16,0
endon
---------------------------------------------
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
Re: Publishing GPIO state via MQTT on bootup and timer
with your confirmation, i assume is a problem with r105,
i will check with the update to r107, if it is/was a bug in this specific firmware..
i will check with the update to r107, if it is/was a bug in this specific firmware..
Re: Publishing GPIO state via MQTT on bootup and timer
@tozett, do you still have rules problems? I still have, not sure what to do next.
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
Re: Publishing GPIO state via MQTT on bootup and timer
My rules are ok, in general.
I didn't had time to check if 'Pubish' is working.
As soon as I tested, i will Report back...
I didn't had time to check if 'Pubish' is working.
As soon as I tested, i will Report back...
Re: Publishing GPIO state via MQTT on bootup and timer
i am on r106 and mqtt-"Publish" within rules is working.
(which is fantastic, i can send mqtt-payload messages from rules...)
i can confirm. (edit: also r107 is working, i upgraded and tested succesfully)
my rules looks like:
(which is fantastic, i can send mqtt-payload messages from rules...)
i can confirm. (edit: also r107 is working, i upgraded and tested succesfully)
my rules looks like:
Code: Select all
On rfid#Tag do
gpio,13,0
timerSet,1,2
//this seem to work on r107...
Publish ESP/03/Haustuer/Key,[rfid#tag]
//disabled action
if [rfid#Tag]=25323
//SendToUDP,192.168.14.204,8899,Haustuer [rfid#Tag]%
endif
endon
Re: Publishing GPIO state via MQTT on bootup and timer
So after looking at this, it occurred to me that is might be nice if we could get the boot cause via MQTT when the unit boots. Also maybe when the connection error gets close to the reboot level to get the count and Uptime, although if it is resetting because there is no MQTT connection that may not help. In any case, knowing it rebooted and why could be useful for troubleshooting.
Has anyone tried this, or is it even possible at this point?
Has anyone tried this, or is it even possible at this point?
Who is online
Users browsing this forum: Ahrefs [Bot] and 23 guests