Publishing GPIO state via MQTT on bootup and timer

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
trokkie
New user
Posts: 4
Joined: 19 Apr 2016, 11:15

Publishing GPIO state via MQTT on bootup and timer

#1 Post by trokkie » 19 Apr 2016, 11:42

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...

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#2 Post by tozett » 19 Apr 2016, 12:36

May you use the rules Option?
Here in the forum are examples for usage...

trokkie
New user
Posts: 4
Joined: 19 Apr 2016, 11:15

Re: Publishing GPIO state via MQTT on bootup and timer

#3 Post by trokkie » 19 Apr 2016, 14:41

Ah...thank you, I will try it and give feedback. I was not aware of Rules, I used to work with release 78.

Allycat1972
Normal user
Posts: 25
Joined: 19 Apr 2016, 11:12

Re: Publishing GPIO state via MQTT on bootup and timer

#4 Post by Allycat1972 » 26 Apr 2016, 10:35

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.

trokkie
New user
Posts: 4
Joined: 19 Apr 2016, 11:15

Re: Publishing GPIO state via MQTT on bootup and timer

#5 Post by trokkie » 09 May 2016, 10:19

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

BertB
Normal user
Posts: 1049
Joined: 25 Apr 2015, 14:39

Re: Publishing GPIO state via MQTT on bootup and timer

#6 Post by BertB » 09 May 2016, 11:50

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

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#7 Post by tozett » 09 May 2016, 14:43

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:

Code: Select all

gpio,2,0 // close valve
and misleading here:

Code: Select all

timerSet,1,30      //Set Timer1 for the next event in 30 seconds
timerSet 1,600 // 10 minute timer
it would be more logical to have this comma also with

Code: Select all

sendTo 2,event,givemesomewater (to use the previous example.
and

Code: Select all

Publish <topic>,<value>
--------edit:
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.

trokkie
New user
Posts: 4
Joined: 19 Apr 2016, 11:15

Re: Publishing GPIO state via MQTT on bootup and timer

#8 Post by trokkie » 10 May 2016, 00:19

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

farhanito
New user
Posts: 9
Joined: 10 May 2016, 16:15

Re: Publishing GPIO state via MQTT on bootup and timer

#9 Post by farhanito » 12 May 2016, 16:00

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
Problem is when both esp and broker (and wifi) dead,
esp boots faster than the broker, so the rule won't work

Allycat1972
Normal user
Posts: 25
Joined: 19 Apr 2016, 11:12

Re: Publishing GPIO state via MQTT on bootup and timer

#10 Post by Allycat1972 » 13 May 2016, 14:19

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 :lol:

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#11 Post by tozett » 13 May 2016, 19:50

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?
Attachments
Zwischenablage01-publish.png
Zwischenablage01-publish.png (129.82 KiB) Viewed 20055 times

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#12 Post by tozett » 13 May 2016, 20:00

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
Attachments
Zwischenablage02-publish.png
Zwischenablage02-publish.png (47.1 KiB) Viewed 20055 times

farhanito
New user
Posts: 9
Joined: 10 May 2016, 16:15

Re: Publishing GPIO state via MQTT on bootup and timer

#13 Post by farhanito » 14 May 2016, 08:06

The default Subscribe template is /%sysname%/#

So, try Publish /ESP/03/...

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#14 Post by tozett » 14 May 2016, 08:24

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?

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Publishing GPIO state via MQTT on bootup and timer

#15 Post by JR01 » 24 May 2016, 20:21

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
---------------------------------------------
-----------
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.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#16 Post by tozett » 25 May 2016, 07:18

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..
:roll:

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Publishing GPIO state via MQTT on bootup and timer

#17 Post by JR01 » 27 May 2016, 08:20

@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.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#18 Post by tozett » 27 May 2016, 08:32

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...

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Publishing GPIO state via MQTT on bootup and timer

#19 Post by tozett » 28 May 2016, 10:48

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:

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

Drum
Normal user
Posts: 300
Joined: 07 Feb 2016, 11:56

Re: Publishing GPIO state via MQTT on bootup and timer

#20 Post by Drum » 14 Jun 2016, 16:21

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?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 23 guests