Page 1 of 1

PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 12:57
by Oetsch
Hi

tried to use the Monitor function of a GPIO to trigger a command, but this doesn´t work because GPIO is used for PWM control and out of the docu the Monitor function can only detect binary 0/1 change.

Can you recommand how to trigger based on PWM change (all changes, not dedicated range or value)?
Thx!

Code: Select all

on System#Boot do
Monitor GPIO,12
gpio,12,0
endon

on GPIO#12 do    
Publish %sysname%/GPIO/GPIO12,[Plugin#GPIO#Pinstate#12] 
endon

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 14:33
by TD-er
As you already found out, the monitor command doesn't trigger events when PWM changes.
Not sure if we can simply detect it via an interrupt. (we should be able to trigger an event when ESPEasy gives the command to change PWM though)

So I wonder how the PWM gets changed?
Is it set via ESPEasy rules?

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 14:47
by Oetsch
Hi
the PWM is set via the http command:

Code: Select all

http://<ESP IP address>/control?cmd=PWM,<pin>,<level>
Also tried based on the log to trigger on the PWM* or HTTP* but I guess this is just a message in the log and not a real event to be used as trigger.

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 14:54
by Ath
To avoid that an external system has to know the pin number, you'd better (Best Practice...) use an event to set the PWM value:

Code: Select all

http://<ESP IP address>/control?cmd=event,FANPWM=<level>
and in rules have:

Code: Select all

on fanpwm do
  PWM,12,%eventvalue1%
  Publish %sysname%/GPIO/GPIO12,[Plugin#GPIO#Pinstate#12]
endon
Recent versions of ESPEasy will provide the PWM state when used as above via this (merged) PR: https://github.com/letscontrolit/ESPEasy/pull/4435

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 15:02
by Oetsch
Thx Ton

Question for my understanding, the event name "FANPWM" has not to be known or registered in ESPEasy? I can feel free to use "every" name?

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 15:05
by Ath
Well, it shouldn't be too long, and not contain spaces, commas, #, =, /, etc, as that would cause issues while parsing the rules :lol: and also not be the name of an existing command etc.

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 15:10
by Oetsch
Thx! that´s ovious but fanpwm is not a predefined name with functionality in the background of ESPEasy.

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 15:28
by Ath
I'm not sure what it is actually controlling, but usually when using the PWM command that's related to a LED, fan or pump. I just, sort of random, chose fan this time :)

Re: PWM change as Trigger (Rule) ?

Posted: 30 Aug 2023, 15:30
by TD-er
Nope, it is not an internal command.
Just something you may pick, which makes it clear what it does.

You can also use "fanspeed" or "niceweathertoday", although I don't think the last one will be clear what it does :)

Re: PWM change as Trigger (Rule) ?

Posted: 31 Aug 2023, 14:12
by Oetsch
:lol: Thx!