How to ask a ESPeasy device of a GPIO state?

Moderators: BertB, rtenklooster, Voyager, Stuntteam, Martinus

Message
Author
xbmcnut
Normal user
Posts: 42
Joined: 17 Mar 2016, 08:49
Location: Auckland, NZ
Contact:

Re: How to ask a ESPeasy device of a GPIO state?

#11 Post by xbmcnut » 10 Aug 2016, 00:30

Martinus wrote:
Stefan wrote:
It's a system wide command and should work on serial, http and mqtt.
For mqtt, send the command as payload to <subscription template>/cmd
For mqtt, the result is send on <subscription template>/status
Could you possibly clarify the MQTT command for obtaining a GPIO status? You mention <subscription template>/status but in my case if I subscribe to /ESP01/status/#, nothing is ever received. Tried with R108.
Numerous Sonoff's, Home Assistant on Pi3, Vera 2 for Z-wave, ha-bridge for voice control with 3 x Echo Dot's and 2 x Google Home

Martinus
Normal user
Posts: 887
Joined: 16 Apr 2015, 17:21

Re: How to ask a ESPeasy device of a GPIO state?

#12 Post by Martinus » 10 Aug 2016, 09:30

Testlab setup:

ESP name: ESPDemo
Template: /%sysname%/#

Publish gpio,2,0 to /ESPDemo/cmd

Receiving this on /ESPDemo/status:

{
"log": "GPIO 2 Set to 0",
"plugin": 1,
"pin": 2,
"mode": "output",
"state": 0
}



Publish status,gpio,2 to /ESPDemo/cmd

Receiving this on /ESPDemo/status:

{
"log": "",
"plugin": 1,
"pin": 2,
"mode": "output",
"state": 0
}


Every command that's documented for HTTP should also work if send to .../cmd topic using MQTT.
Instead of returning a web page, it reports back to ..../status

xbmcnut
Normal user
Posts: 42
Joined: 17 Mar 2016, 08:49
Location: Auckland, NZ
Contact:

Re: How to ask a ESPeasy device of a GPIO state?

#13 Post by xbmcnut » 10 Aug 2016, 11:27

Martinus wrote:Testlab setup:

Every command that's documented for HTTP should also work if send to .../cmd topic using MQTT.
Instead of returning a web page, it reports back to ..../status
Thank you, that is awesome to know! I now get the following when I publish to /ESP01/cmd with gpio,14,0.

Code: Select all

{
"log": "GPIO 14 Set to 0",
"plugin": 1,
"pin": 14,
"mode": "output",
"state": 0
}
Home Assistant however is expecting either a 1 or 0 from its MQTT components so I'm trying to just get a status back with that data and nothing else. Is that possible? You mention sending MQTT ...cmd (which is what I did above) but I got the json response back. I see I may be able to use the 'value_template' to pull data from the json payload but that's getting a bit over my head.
Numerous Sonoff's, Home Assistant on Pi3, Vera 2 for Z-wave, ha-bridge for voice control with 3 x Echo Dot's and 2 x Google Home

User avatar
JR01
Normal user
Posts: 164
Joined: 14 Feb 2016, 21:04
Location: South Africa
Contact:

Re: How to ask a ESPeasy device of a GPIO state?

#14 Post by JR01 » 10 Aug 2016, 12:08

Thank you Martinus ! Now I understand how it works, was not sure about the /cmd part on how to use it.

I prefer the json file format, its the standard moving forward in the industry, and give me flexibility on what I can do with it. It also allows our ESPEasy code and framework not to be bloated with different code for what each individual expect the output needs to be, but that ons does that in the integration layer.

Regarding only expecting 0/1 back from the previous post, I use node-red with mqtt, and thus easy with a function node, after receiving the mqtt message to transform the json to say a zero or 1. I know the other platforms like OpenHab / Domostisz etc can also do it (I do not have experience with it though, but read up how this works).

Thank you Martinus again, this is a huge step forward! (for me - to cover the full arch)

User avatar
ThinkPad
Normal user
Posts: 5
Joined: 20 Jun 2016, 12:04

Re: How to ask a ESPeasy device of a GPIO state?

#15 Post by ThinkPad » 10 Aug 2016, 22:59

xbmcnut wrote: [...]
Home Assistant however is expecting either a 1 or 0 from its MQTT components so I'm trying to just get a status back with that data and nothing else. Is that possible? You mention sending MQTT ...cmd (which is what I did above) but I got the json response back. I see I may be able to use the 'value_template' to pull data from the json payload but that's getting a bit over my head.
This doesn't has to be very difficult, have a look at this where they create a template to do this: https://groups.google.com/forum/#!topic ... RqwZPCNbaw
See also https://home-assistant.io/components/switch.mqtt/ for more information about a MQTT in HA.

Very interesting stuff btw. I have Home Assistant running for a little more than a week now (mostly with Z-Wave stuff) but ESPEasy is a very nice addition i think. Especially with boards like the Wemos D1 Mini which already have the necessary components on board (voltage converter, USB-Serial etc). Haven't done anything with MQTT yet, i think i will need to have a look at it sometime, seems interesting.

xbmcnut
Normal user
Posts: 42
Joined: 17 Mar 2016, 08:49
Location: Auckland, NZ
Contact:

Re: How to ask a ESPeasy device of a GPIO state?

#16 Post by xbmcnut » 11 Aug 2016, 00:13

ThinkPad wrote:
xbmcnut wrote:
This doesn't has to be very difficult, have a look at this where they create a template to do this: https://groups.google.com/forum/#!topic ... RqwZPCNbaw
See also https://home-assistant.io/components/switch.mqtt/ for more information about a MQTT in HA.
This seems significantly more difficult than just adopting the MQTT standard for polling the broker for the 'retain' flag which is how the Home Assistant core is working with their MQTT components. This is the problem I'm having with ESPEasy. I've configured a switch on the same gpio as the one I'm controlling using /ESP01/gpio/14 (0 or 1) and now get a reply back on /ESP01/relay14/state but this message does not contain the retain flag. This all works fine and dandy until Home Assistant is restarted and it polls the broker for the last know state. Without the retain flag, the switch status always drops back to 0 or off.
Numerous Sonoff's, Home Assistant on Pi3, Vera 2 for Z-wave, ha-bridge for voice control with 3 x Echo Dot's and 2 x Google Home

User avatar
ThinkPad
Normal user
Posts: 5
Joined: 20 Jun 2016, 12:04

Re: How to ask a ESPeasy device of a GPIO state?

#17 Post by ThinkPad » 11 Aug 2016, 20:19

I didn't knew that (or even worse: i don't know anything at all from MQTT yet :mrgreen: ).

xbmcnut
Normal user
Posts: 42
Joined: 17 Mar 2016, 08:49
Location: Auckland, NZ
Contact:

Re: How to ask a ESPeasy device of a GPIO state?

#18 Post by xbmcnut » 12 Aug 2016, 14:44

This is now working as the retain flag option has been added in R121 and it works a treat.

http://www.esp8266.nu/forum/viewtopic.p ... 8545#p8545
Numerous Sonoff's, Home Assistant on Pi3, Vera 2 for Z-wave, ha-bridge for voice control with 3 x Echo Dot's and 2 x Google Home

User avatar
lucaberta
Normal user
Posts: 32
Joined: 09 May 2016, 11:26

Re: How to ask a ESPeasy device of a GPIO state?

#19 Post by lucaberta » 24 Aug 2016, 00:41

Hi Martinus,

I am testing the feature you have enhanced a few weeks ago with a similar lab setup as yours:
Martinus wrote:Testlab setup:

ESP name: ESPDemo
Template: /%sysname%/#

Publish gpio,2,0 to /ESPDemo/cmd

Receiving this on /ESPDemo/status:

{
"log": "GPIO 2 Set to 0",
"plugin": 1,
"pin": 2,
"mode": "output",
"state": 0
}


[...]

Every command that's documented for HTTP should also work if send to .../cmd topic using MQTT.
Instead of returning a web page, it reports back to ..../status
but I believe I have found a bug somewhere in how the publish template is used somewhere in the code.

As I have decided to NOT have a leading slash in my template, nothing was working. When I added the slash in the Advanced tab, and changed the MQTT paths accordingly, things started to work.

I did not have any time to check the code of R123 which is what I am using now, but I suspect that somewhere in the code lies an hardcoded slash where it shouldn't be...

I'll do some checking tomorrow. Meanwhile if you have any idea of where the problem lies, let me know!

MvG, Luca

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests