Switching Lights on/off with PIR if already on

Moderator: leecollings

Post Reply
kcp601
Posts: 3
Joined: Tuesday 21 February 2017 1:15
Target OS: Windows
Domoticz version:
Contact:

Switching Lights on/off with PIR if already on

Post by kcp601 »

Hi all,

This sensor is my first foray into the IoT world using Mysensors & arduino! I may be being completely dim, but essentially I would like the following to happen:

When I walk past the PIR the ceiling light should switch on. If the ceiling light is already on and I walk past, it should switch off. So far I have the following:
2017-02-21 00_28_39-Domoticz.png
2017-02-21 00_28_39-Domoticz.png (16.94 KiB) Viewed 2473 times
But it doesn't seem to want to play ball. The only thing I can think of is that it may get stuck in a loop after that because the PIR would still be on?

Any help would be appreciated! :D
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Switching Lights on/off with PIR if already on

Post by tozzke »

Although it's an odd situation you want to accomplish... You'll have to add a state for every device, so you'll get something like:

Code: Select all

If [Security sensor = On] and [ceiling = Off]
Do [Set ceiling = On]
Else if [Security sensor = On] and [ceiling = On]
Do [Set ceiling = Off]
Only I think this won't work as you planned because when the first condition is met (and a sensor usually stays on for a certain amount of time after detecting motion) the second condition is true which will turn the ceiling off again. This means the first condition is met again so it'll turn the ceiling back on again etc....
You 'll have to add a variable for instance for this to work properly so you'll get something like this:

Code: Select all

If [Security sensor = On] and [ceiling = Off] and [var ceiling = 0]
Do [Set ceiling = On]
Do [Set var ceiling = 1]
Do [Set var ceiling = 2 after 10* seconds]
Else if [Security sensor = On] and [ceiling = On] and [var ceiling = 2]
Do [Set ceiling = Off]
Do [Set var ceiling = 3]
Do [Set var ceiling = 0 after 10* seconds]
* set this time a bit longer than the sensor stays on after detecting motion

quick'ndirty :)

You could also use a dummy switch with an off delay set to a bit longer than the sensor stays on
kcp601
Posts: 3
Joined: Tuesday 21 February 2017 1:15
Target OS: Windows
Domoticz version:
Contact:

Re: Switching Lights on/off with PIR if already on

Post by kcp601 »

Thanks for the reply! I've tried popping that in but I get the error

Code: Select all

2017-02-22 22:40:39.646 Error: EventSystem: in ce: [string "If [pir = On] and [ceiling = Off] and [var ce..."]:1: ']' expected near '='
Do I need to be defining local variables or something else? I've looked at other examples and can't see anything wrong! I changed the name of 'security sensor' just in case it was the space that was confusing it but no joy with that either...

The exact script I now have is

Code: Select all

If [pir = On] and [ceiling = Off] and [var ceiling = 0]
Do [Set ceiling = On]
Do [Set var ceiling = 1]
Do [Set var ceiling = 2 after 10 seconds]
Else if [pir = On] and [ceiling = On] and [var ceiling = 2]
Do [Set ceiling = Off]
Do [Set var ceiling = 3]
Do [Set var ceiling = 0 after 10 seconds]
end
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Switching Lights on/off with PIR if already on

Post by NietGiftig »

not

Code: Select all

"If [pir = On] and [ceiling = Off]
but

Code: Select all

"If [pir == On] and [ceiling == Off]
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Switching Lights on/off with PIR if already on

Post by tozzke »

kcp601 wrote:Thanks for the reply! I've tried popping that in but I get the error

Code: Select all

2017-02-22 22:40:39.646 Error: EventSystem: in ce: [string "If [pir = On] and [ceiling = Off] and [var ce..."]:1: ']' expected near '='
Do I need to be defining local variables or something else? I've looked at other examples and can't see anything wrong! I changed the name of 'security sensor' just in case it was the space that was confusing it but no joy with that either...

The exact script I now have is

Code: Select all

If [pir = On] and [ceiling = Off] and [var ceiling = 0]
Do [Set ceiling = On]
Do [Set var ceiling = 1]
Do [Set var ceiling = 2 after 10 seconds]
Else if [pir = On] and [ceiling = On] and [var ceiling = 2]
Do [Set ceiling = Off]
Do [Set var ceiling = 3]
Do [Set var ceiling = 0 after 10 seconds]
end
you aren't adding this as lua are you?
I made a blockly in text :p
please add a screenshot of what you made
kcp601
Posts: 3
Joined: Tuesday 21 February 2017 1:15
Target OS: Windows
Domoticz version:
Contact:

Re: Switching Lights on/off with PIR if already on

Post by kcp601 »

Ahhh, that was the problem! I now have the below, which I think is right? Not had a chance to test it yet. The idea was that when I walked into the room, the light would turn on and when I walked out, if it was already on it would turn off. What I didn't take into account though, is if someone else walks in to the room whilst I'm also in the room! May have to look at an addition one in the room that detects if I'm moving around in the room. Thanks for all your help!
Screen Shot 2017-03-01 at 23.28.57.png
Screen Shot 2017-03-01 at 23.28.57.png (117.83 KiB) Viewed 2276 times
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Switching Lights on/off with PIR if already on

Post by tozzke »

does it work as you expected?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest