Page 1 of 1
Switching Lights on/off with PIR if already on
Posted: Tuesday 21 February 2017 1:30
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 (16.94 KiB) Viewed 2555 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!

Re: Switching Lights on/off with PIR if already on
Posted: Tuesday 21 February 2017 6:30
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
Re: Switching Lights on/off with PIR if already on
Posted: Wednesday 22 February 2017 23:42
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
Re: Switching Lights on/off with PIR if already on
Posted: Thursday 23 February 2017 0:12
by NietGiftig
not
Code: Select all
"If [pir = On] and [ceiling = Off]
but
Code: Select all
"If [pir == On] and [ceiling == Off]
Re: Switching Lights on/off with PIR if already on
Posted: Thursday 23 February 2017 22:00
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
Re: Switching Lights on/off with PIR if already on
Posted: Thursday 02 March 2017 0:32
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 (117.83 KiB) Viewed 2358 times
Re: Switching Lights on/off with PIR if already on
Posted: Saturday 04 March 2017 17:33
by tozzke
does it work as you expected?