Trigger Mointor GPIO event (was resolved quickly)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Trigger Mointor GPIO event (was resolved quickly)

#1 Post by Dondolo » 21 Mar 2021, 14:18

Hi,

I switch a GPIO with http: //192....=gpio,15,1.
I want to monitor the GPIO using the Monitor, GPIO, 15 command.
How can I trigger an event when the value changes?

I tried the following rule:

Code: Select all

on System#Boot do
Monitor,GPIO,15
endon

on plugin#gpio#pinstate#15 do
Publish,%sysname%/GPIO/Lüfter,[plugin#gpio#pinstate#15]
TaskValueSet 12,1,[plugin#gpio#pinstate#15]
endon

on [plugin#gpio#pinstate#15]=1 do
Publish,%sysname%/GPIO/Lüfter,[plugin#gpio#pinstate#15]
TaskValueSet 12,1,[plugin#gpio#pinstate#15]
endon

on [plugin#gpio#pinstate#15]=0 do
Publish,%sysname%/GPIO/Lüfter,[plugin#gpio#pinstate#15]
TaskValueSet 12,1,[plugin#gpio#pinstate#15]
endon
Last edited by Dondolo on 21 Mar 2021, 17:11, edited 1 time in total.

GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

Re: Trigger Mointor GPIO event

#2 Post by GravityRZ » 21 Mar 2021, 15:52

really easy

Code: Select all

On GPIO#15=0 do
do your stuff
Endon	

On GPIO#15=1 do
do your stuff
Endon

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Trigger Mointor GPIO event

#3 Post by TD-er » 21 Mar 2021, 16:39

Also using %eventvalue1% in your rules may make things a lot simpler:

Code: Select all

on GPIO#15 do
  Publish,%sysname%/GPIO/Lüfter,%eventvalue1%
  TaskValueSet 12,1,%eventvalue1%
endon
One thing I am not sure about is whether the umlaut in the topic is working.
I don't know what character(s) is sent here and also if the MQTT broker may translate extended ASCII into the same Unicode character to match the topic.
ESPEasy itself does nothing special regarding Unicode characters. It just considers them as (signed) 8 bit characters and thus does not perform any conversion.

Another thing to keep in mind.
Never use [] in the on...do part of the rules.
A [] syntax is used to replace what's inside.

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Trigger Mointor GPIO event (was resolved quickly)

#4 Post by Dondolo » 21 Mar 2021, 17:12

Thank you for the quick solution!

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Trigger Mointor GPIO event (was resolved quickly)

#5 Post by Dondolo » 28 Mar 2021, 13:19

Also using %eventvalue1% in your rules may make things a lot simpler:
I still have a question when the ESP reboots, how can I query the GPIO status and send it to the broker with publish?


Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Trigger Mointor GPIO event (was resolved quickly)

#7 Post by Dondolo » 28 Mar 2021, 14:46

I'm sorry, have to ask again.
What does the rule have to look like so that the GPIo status is published?
This is not how it works:

Code: Select all


on System#Boot do
Monitor,GPIO,14
timerSet,1,10
let,1,[Plugin#GPIO#Pinstate#14]
endon

on MQTT#Connected do
Publish,Test/GPIO14,[var#1]
TaskValueSet 12,1,[var#1]
endon

on GPIO#14 do
  Publish,Test/GPIO,%eventvalue1%
endon


TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Trigger Mointor GPIO event (was resolved quickly)

#8 Post by TD-er » 28 Mar 2021, 14:53

Are you interested in the state at boot, or when you publish it on MQTT#connected ?
Also you're publishing to 2 different topics. Is that intentional?

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Trigger Mointor GPIO event (was resolved quickly)

#9 Post by Dondolo » 28 Mar 2021, 16:20

Are you interested in the state at boot, or when you publish it on MQTT#connected ?

The background is, I use Iobroker with the Jarves View. There I switch a relay on the ESP (espeasy) with blockly script.
When switching, the command goes e.g.
http: //192.168.xxx.xx/control? cmd = gpio, 15.1
Out. -Light is on-

When the ESP boots, the GPIO status (lamp on / off) should be published via mqtt. -Query when booting-
When switching, the GPIO status (on / off - 0/1) changes as planned - query in operation-

Hence different topics
I am not sure whether the GPIO status is transmitted at all when booting. There is still no connection to the broker via mqtt.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Trigger Mointor GPIO event (was resolved quickly)

#10 Post by TD-er » 28 Mar 2021, 18:25

I do understand why you want to publish it at mqtt#connected.
But I don't know how long it takes till you have a connection, so maybe it is not the best idea to publish the state as it was at boot, but rather the actual state.

Code: Select all

on MQTT#Connected do
  Publish,Test/GPIO14,[Plugin#GPIO#Pinstate#14]
endon

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests