External GPIO handling (MQTT or HTTP) + Rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

External GPIO handling (MQTT or HTTP) + Rules

#1 Post by Oetsch » 13 Jul 2020, 12:33

Hi everybody,

I´m pretty new in doing such stuff so please be so kind in helping me to help myself :)

For automation of rain water system (tanks + valves etc.) I´d like to have an local interface via espeasy which also should allow external access by IObroker.
So first I have implemented a level sensor and show the level on local display. These level is also published by openHab Mqtt to IObroker.
Now I like to have two local push buttons (START & STOP) to activate a pump which is not connected locally so I need this status information external by mqtt for example. In addition I´d like to have 2 local LEDs (red & green) which indecates the status of the pump.

My idea is to create 2 virtual switches inside of the espeasy (LED_START & LED_Stop) which also switches the gpio of the corresponding LED (guess this should be done via a rule) and the virtual switch have to be send to controller to have also available in the external system (IObroker) for indication and start&stop of the pump. Beside the rule for the switch/gpio where i´m struggeling is the external switch by mqtt. The external change of such a switch from false to true is not communicated to the espeasy. Why and how to solve?
Is it because MQTT values cannot be operated directly in an external system? So I have to send and command via mqtt like an http command to the espeasy?
I tried as an example also via Generic MQTT Import but this also does not work for me. Is it because only float or integer and no status information can be used by Mqtt Import?

Kindly ask for help how you would solve this what should be best to solve?
Please also consider that I´m already using a PSF8574 for addtional IO at my Wemos D1 Mini and so I´m limited in using the available 12 devices for virtual switches e.g.

Thank you very much in advance!
Attachments
esp.JPG
esp.JPG (137.62 KiB) Viewed 11641 times

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: External GPIO handling (MQTT or HTTP) + Rules

#2 Post by ThomasB » 16 Jul 2020, 04:40

Like you, I am using OpenHAB with ESPEasy devices. Although communication from ESPEasy to OH2 is via MQTT, the commands from OH2 to ESPEasy use http (OH2's sendHttpPutRequest rule command).

It's not clear to me but I think you are saying MQTT messages from ESPeasy to OH2 are working. So all you need is to add the rules in OH2 that send event commands to ESPEasy via http.

For example, create an ESPEasy rule event named LED_START that does the LED actions you need. Then trigger the LED_START event from a OH2 rule like this:
sendHttpPutRequest(<espeasyip>/control?cmd=Event,LED_START) // note: <espeasyip> = YOUR device IP address.

- Thomas

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: External GPIO handling (MQTT or HTTP) + Rules

#3 Post by Oetsch » 17 Jul 2020, 13:20

Thx Thomas

I´m using the Smart Home Automation Software IOBROKER and OpenHab is only used as MQTT Interface(Configuration in ESPEasy). At the Moment ESPEasy to IOBROKER works fine. But e.g. when I switch States of these MQTT Datapoints inside of IOBroker this changes are not published/transfered to ESPEasy.

Yesterday I found a topic where the structure of the subscription is shown as the problem because this has to be in a special/direct structure.
e.g. in case I like to switch GPIO 2 the controller subscription has to be /Heiz_Keller/GPIO/2

without a description of the espeasy device in between etc.

If I do it like this the communication should work in both directions. Currently I cannot test it because ì´m working via remote connection and by doing an online upgrade I "killed" the Wemos D1 mini. So have to fix it locally.

The http commands work for me to switch the GPIOs but I don´t really like this because the configuration is stick/fix to IP-Adresses and has to be adjusted in many configuration blocks inside of the programming in case I change sth. Linking to the MQTT Datapoint is much more generic and therefore easier to handle from my perpective.

So at the moment I believe creating Devices inside of espeasy for the LEDs is not necessary anymore for me. For the Switches I think I have to create switches and bceause I´m using push buttons I will have to create rules to define what should happen and lock specific situation for safety or unwanted reasons, right?
Of course, I only want to do basic and important stuff by rules inside of espeasy to have it also functionable when wifi connection might be disturbed. The more "advanced" programming like automated filling and emtying processes (similar to Sequence Function Charts) should be done in IObroker.

First time for me using LEDs and Switches in ESPEasy and therefore I´m unsure what to do for a good way (ressource effecient way). Still believe 12 devices is max what is possible in espeasy, right?

In Addition when thinking about rules, is it possible to use the status of a GPIO as trigger? I have only seen as trigger e.g. switches but no GPIOs directly is this possible? Otherwise I have to create switches for the LEDs only therefore...

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests