Page 1 of 1

Trigger Mointor GPIO event (was resolved quickly)

Posted: 21 Mar 2021, 14:18
by Dondolo
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

Re: Trigger Mointor GPIO event

Posted: 21 Mar 2021, 15:52
by GravityRZ
really easy

Code: Select all

On GPIO#15=0 do
do your stuff
Endon	

On GPIO#15=1 do
do your stuff
Endon

Re: Trigger Mointor GPIO event

Posted: 21 Mar 2021, 16:39
by TD-er
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.

Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 21 Mar 2021, 17:12
by Dondolo
Thank you for the quick solution!

Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 28 Mar 2021, 13:19
by Dondolo
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?

Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 28 Mar 2021, 13:45
by TD-er

Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 28 Mar 2021, 14:46
by Dondolo
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


Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 28 Mar 2021, 14:53
by TD-er
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?

Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 28 Mar 2021, 16:20
by Dondolo
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.

Re: Trigger Mointor GPIO event (was resolved quickly)

Posted: 28 Mar 2021, 18:25
by TD-er
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