Rules again follow-up

Moderators: grovkillen, Stuntteam, TD-er

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

Re: Rules again follow-up

#51 Post by Ath » 22 Feb 2023, 21:37

That can't be all rules, as then there is nothing calling this one rule.
To get the full picture I need to see all rules code...
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules again follow-up

#52 Post by Dick60 » 22 Feb 2023, 21:43

This was not the latest solution from IT aadmin but it was alost a full working solution. After my change it worked completely

Code: Select all

on UpdateLightIntensity do
  if [Plugin#GPIO#Pinstate#2]=0 and [int#1]=1
    // Manual mode is not active, and no recent motion detected.
    // So we must turn off the lights.
    gpio,10,1
    gpio,13,1
but still it is not logic for me and have my doubt if the variable is loaded.

Add 2 logentry rows of the variables are set but this is all.

Code: Select all

on System#Boot do
 Monitor GPIO,0 // PIR sensor
 Monitor GPIO,2 // Manual mode
endon

on GPIO#0=1 do
  // PIR motion detected
  if [Plugin#GPIO#Pinstate#2]=0
    // Manual mode is not active, so we must act on the motion sensor
    timerSet,1,1800 // 30 minutes timer
    let,1,1 // Set variable #1 to indicate we had some motion detected  
    LogEntry,"var#1: [var#1] A1"
    asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]
  endif
endon

on GPIO#2 do
  // Change of "manual mode"
  asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]
endon


On serre_lichtmeting#Analog do
  asyncevent,UpdateLightIntensity=%eventvalue1%
endon

on Rules#Timer=1 do
  // 30 minutes has past with no motion detected
  let,1,0 // Clear variable #1 to indicate no motion was detected.
  LogEntry,"var#1: [var#1] A2"
  asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]
endon

on UpdateLightIntensity do
  if [Plugin#GPIO#Pinstate#2]=0 and [int#1]=1
    // Manual mode is not active, and no recent motion detected.
    // So we must turn off the lights.
    gpio,10,1
    gpio,13,1
    LogEntry,"Intensity: %eventvalue1% pwm: n/a gpio: 0  A"
  else
    // Either manual mode is active, or recently detected motion
    If %eventvalue1%<60
      PWM,16,00
    Elseif %eventvalue1%<450
gpio,10,1
gpio,13,1
LogEntry,"Intensity: %eventvalue1% pwm: n/a gpio: 0  B"
      let,1,2.5*%eventvalue1%-125 // Approximation of the curve
      PWM,16,[int#1]
    Else
      PWM,16,1000
      GPIO,10,1
      GPIO,13,1      
      LogEntry,"Intensity: %eventvalue1% pwm: n/a gpio: 0  C"
    Endif
  endif
endon

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

Re: Rules again follow-up

#53 Post by Ath » 22 Feb 2023, 22:02

Not sure why, but your current copy of "on UpdateLightIntensity do" doesn't match with the last edition I gave in post #47.
Can you update that part with a complete copy of that code?

This is what is expected to be in your rules: (Use the "Select all" link at the top and then ctrl-C to copy it completely)

Code: Select all

on System#Boot do
 Monitor GPIO,0 // PIR sensor
 Monitor GPIO,2 // Manual mode
endon

on GPIO#0=1 do
  // PIR motion detected
  if [Plugin#GPIO#Pinstate#2]=0
    // Manual mode is not active, so we must act on the motion sensor
    timerSet,1,1800 // 30 minutes timer
    let,1,1 // Set variable #1 to indicate we had some motion detected  
    LogEntry,"var#1: [var#1] A1"
    asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]
  endif
endon

on GPIO#2 do
  // Change of "manual mode"
  asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]
endon


On serre_lichtmeting#Analog do
  asyncevent,UpdateLightIntensity=%eventvalue1%
endon

on Rules#Timer=1 do
  // 30 minutes has past with no motion detected
  let,1,0 // Clear variable #1 to indicate no motion was detected.
  LogEntry,"var#1: [var#1] A2"
  asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]
endon

on UpdateLightIntensity do
  if [Plugin#GPIO#Pinstate#2]=0 and [int#1]=0
    // Manual mode is not active, and no recent motion detected.
    // So we must turn off the lights.
    gpio,10,0
    gpio,13,0
    LogEntry,"Intensity: %eventvalue1% pwm: n/a gpio: 0  A"
  else
    // Either manual mode is active, or recently detected motion
    If %eventvalue1%<60
      // Option #1 Will turn off 10 and 13 because LightIntensity <60
      GPIO,10,0
      GPIO,13,0
      PWM,16,00
      LogEntry,"Intensity: %eventvalue1% pwm: 0 gpio: 0  B"
    Elseif %eventvalue1%<450
      let,1,2.5*%eventvalue1% - 125 // Approximation of the curve
      PWM,16,[int#1]
      GPIO,10,1  // Option 2 Will turn on 10 and 13 because LightIntensity >= 60
      GPIO,13,1
      LogEntry,"Intensity: %eventvalue1% pwm: [int#1] gpio: 1  C"
    Else
      PWM,16,1000
      GPIO,10,1  // Option 3 Will turn on 10 and 13 because LightIntensity >= 450
      GPIO,13,1
      LogEntry,"Intensity: %eventvalue1% pwm: 1000 gpio: 1  D"
    Endif
  endif
endon
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules again follow-up

#54 Post by Dick60 » 22 Feb 2023, 22:08

It seems to work now. I see entries in the Log that gpio 10 and 13 are turned on and that is what I missed in the solution I implemented during the day. I test it and hope, tomrrow morning, i get up and movement is is there, the lights turn on. I let you know.

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

Re: Rules again follow-up

#55 Post by Ath » 22 Feb 2023, 22:14

Great :)
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules again follow-up

#56 Post by Dick60 » 23 Feb 2023, 07:50

this morning the light went on entering the room. The switch Beweging went to 1. After 30 min the lights went out, still Beweging switch had the status 1. In my opinion it has to do somenthing with the vaiables and the 30min timer.
This is the log:

173664848: EVENT: serre_lichtmeting#Analog=194
173664856: ACT : asyncevent,UpdateLightIntensity=194
173664863: EVENT: UpdateLightIntensity=194
173664880: ACT : gpio,10,0
173664883: GPIO : port#10: set to 0
173664885: ACT : gpio,13,0
173664887: GPIO : port#13: set to 0
173664890: ACT : LogEntry,'Intensity: 194 pwm: n/a gpio: 0 A'
173664892: Intensity: 194 pwm: n/a gpio: 0 A
173664941: SW : GPIO=13 State=0 Output value=0
173665036: HTTP : C001 192.168.2.244 GET... HTTP code: 200
173665043: EVENT: Stekkers3_kastverlichting#State=0
173665053: EVENT: http#192.168.2.244=200
173665382: HTTP: GPIO,13,0
173665385: GPIO : port#13: set to 0

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

Re: Rules again follow-up

#57 Post by TD-er » 23 Feb 2023, 08:00

It is acting on the change of the state.
So, I guess you need to set the timer to turn it off when the PIR state becomes 0 again instead of 1.

Code: Select all

on GPIO#0 do
  if [Plugin#GPIO#Pinstate#2]=0
    // Manual mode is not active, so we must act on the motion sensor
    if %eventvalue1%=1
      // PIR motion detected
      let,1,1 // Set variable #1 to indicate we had some motion detected  
      LogEntry,"var#1: [var#1] A1"
    else
      // no more motion detected
      // Start timer to turn off lights.
      timerSet,1,1800 // 30 minutes timer
    endif
    asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]    
  endif
endon

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules again follow-up

#58 Post by Dick60 » 23 Feb 2023, 08:56

Now it seems to work. i'm glad to finish this project. Great work!

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

Re: Rules again follow-up

#59 Post by TD-er » 23 Feb 2023, 09:17

There is one more corner-case where it might behave unexpectedly...
But this depends on how often the PIR might toggle.

For example, what if your PIR sensor toggles a few times, since you're sitting still and then start moving a lot for a long time.

Then the timer isn't reset if the motion is detected again.
So we simply need to clear the timer when the PIR state becomes '1' and start the timer again when the PIR changes into '0'.

Code: Select all

on GPIO#0 do
  if [Plugin#GPIO#Pinstate#2]=0
    // Manual mode is not active, so we must act on the motion sensor
    if %eventvalue1%=1
      // PIR motion detected
      timerSet,1,0 // Clear the timer
      let,1,1 // Set variable #1 to indicate we had some motion detected  	  
      LogEntry,"var#1: [var#1] A1"
    else
      // no more motion detected
      // Start timer to turn off lights.
      timerSet,1,1800 // 30 minutes timer
    endif
    asyncevent,UpdateLightIntensity=[serre_lichtmeting#Analog]    
  endif
endon

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: Rules again follow-up

#60 Post by Dick60 » 23 Feb 2023, 18:22

I just saw your last remark and that sound very logic. Befor I add this part I want to say that everything is working now. As soon as the light intensity came above 60 and movement was detected, the lidstrip went on. I add the new part so it is approaching the point of perfection, :D :D

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 28 guests