PWM change as Trigger (Rule) ?

Moderators: grovkillen, Stuntteam, TD-er

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

PWM change as Trigger (Rule) ?

#1 Post by Oetsch » 30 Aug 2023, 12:57

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

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

Re: PWM change as Trigger (Rule) ?

#2 Post by TD-er » 30 Aug 2023, 14:33

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?

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

Re: PWM change as Trigger (Rule) ?

#3 Post by Oetsch » 30 Aug 2023, 14:47

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.

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: PWM change as Trigger (Rule) ?

#4 Post by Ath » 30 Aug 2023, 14:54

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
/Ton (PayPal.me)

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

Re: PWM change as Trigger (Rule) ?

#5 Post by Oetsch » 30 Aug 2023, 15:02

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?

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: PWM change as Trigger (Rule) ?

#6 Post by Ath » 30 Aug 2023, 15:05

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.
/Ton (PayPal.me)

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

Re: PWM change as Trigger (Rule) ?

#7 Post by Oetsch » 30 Aug 2023, 15:10

Thx! that´s ovious but fanpwm is not a predefined name with functionality in the background of ESPEasy.

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: PWM change as Trigger (Rule) ?

#8 Post by Ath » 30 Aug 2023, 15:28

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 :)
/Ton (PayPal.me)

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

Re: PWM change as Trigger (Rule) ?

#9 Post by TD-er » 30 Aug 2023, 15:30

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 :)

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

Re: PWM change as Trigger (Rule) ?

#10 Post by Oetsch » 31 Aug 2023, 14:12

:lol: Thx!

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests