Help - Alarm System and Rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Help - Alarm System and Rules

#1 Post by iz8mbw » 14 Apr 2023, 09:27

Hi all.
I'm thinking to create a house Alarm System with ESPEasy.
For now I have a PIR sensor connected to GPIO-12 as "Switch input - Switch" and it works as expected, so when motion is detected the GPIO-12 is High and I also send the detection via MQTT, all ok it works.

I would like to trigger an alarm siren when motion is detected, so I'm thinking to use another GPIO (GPIO-16) to use as signal to send to the alarm siren.

So my idea is:
When motion is detected (so GPIO-12 High) set to High the GPIO-16 for 30 seconds also if in these 30 seconds the motion is not more detected (so also if GPIO-12 go to Low). In other words I want to hear to the siren for 30 seconds when motion is detected and also if the detection is for only 3 seconds.
Then, when motion is not more detected (so GPIO-12 Low), stop the alarm siren (so GPIO-16 got to Low).
If, after 30 seconds or more, another motion is detected (or detection is still in progress) the alarm siren should still make sound.
Use this behavior forever.


I have created this Rule:

Code: Select all

on motion#Detection=1 do
  GPIO,16,1
  TimerSet,1,20
Endon

On Rules#Timer=1 do
   GPIO,16,0
  endif
 endon
this Rule works well but only if the detection time is less than 30 seconds.

Many thanks for help.

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

Re: Help - Alarm System and Rules

#2 Post by TD-er » 14 Apr 2023, 09:37

Code: Select all

On Rules#Timer=1 do
   GPIO,16,0
  endif
 endon
 
There is only an "endif", not an "if".

Also, what platform are you using? ESP32 or ESP8266?
If it is ESP32, please use another GPIO for the PIR sensor as GPIO-12 on ESP32 is a big no-no to use as input which might be in a specific state during boot as it determines the voltage of the flash chip.

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help - Alarm System and Rules

#3 Post by iz8mbw » 14 Apr 2023, 09:46

Using ESP32.
Ok, I'll go to change GPIO.
Sorry I wrong to copy/paste the Rule, this is the Rule I set:

Code: Select all

on motion#Detection=1 do
  GPIO,16,1
  TimerSet,1,30
Endon

On Rules#Timer=1 do  //When Timer1 expires, do
   GPIO,16,0
   Endon
Thanks.

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

Re: Help - Alarm System and Rules

#4 Post by TD-er » 14 Apr 2023, 09:48

Code: Select all

on motion#Detection do
  if %eventvalue1%=1
    GPIO,16,1
    if [int#1]=0
      TimerSet,1,20
      let,1,1
    endif
  endif
Endon

On Rules#Timer=1 do
   GPIO,16,0
   let,1,0
endon

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help - Alarm System and Rules

#5 Post by iz8mbw » 14 Apr 2023, 09:52

Thanks!!!
Will got to test.

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Help - Alarm System and Rules

#6 Post by iz8mbw » 14 Apr 2023, 15:19

Hi.
The Rule you created works but the as you can see from this log (MQTT), the alarm siren (GPIO-16) starts just after the detection (and it's correct) but at 15:00:49 it stop also if at 2023-04-14 15:00:44 there was another detection.
The detection that started at 15:00:44 ended at 15:00:58 but the alarm siren stop at 15:00:49 (so before the end of detection).

Code: Select all

[2023-04-14 15:00:19] espeasy/motion/Detection 1
[2023-04-14 15:00:19] espeasy/control/Alarm 1
[2023-04-14 15:00:27] espeasy/motion/Detection 0
[2023-04-14 15:00:44] espeasy/motion/Detection 1
[2023-04-14 15:00:49] espeasy/control/Alarm 0
[2023-04-14 15:00:58] espeasy/motion/Detection 0
So it looks like the Alarm start for 30 seconds and it's not able to see the detection status during its alarm (so during the "TimerSet").

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

Re: Help - Alarm System and Rules

#7 Post by Ath » 14 Apr 2023, 16:03

Looks like that can be solved by restarting the timer when a new detection is triggered:

Code: Select all

on motion#Detection do
  if %eventvalue1%=1
    GPIO,16,1
    if [int#1]=0
      let,1,1
    endif
    TimerSet,1,20
  endif
Endon
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests