Page 1 of 1

Only one sensor activate the script

Posted: Tuesday 15 November 2016 7:19
by marigo
I have a script with two motion sensors to turn on the lights. But only one motion sensor (MotionSensor) will actually triggers the script. The "MotionSensor voor" does nothing in this script.

Maybe someone can explain?

Code: Select all

lux = tonumber(otherdevices_svalues['Lichtsensor voor'])
date = os.date("*t")

commandArray = {}

if ((date.hour >= 7 and date.hour <= 23) and
        (devicechanged['MotionSensor'] == 'On' or
        devicechanged['MotionSensor voor'] == 'On')) and
        (otherdevices['Control-Lights'] == 'Off' and
        lux <= 5) then
        commandArray['Group:Schakel-alle-lampen'] = 'On'

elseif (lux >= 14 and
        otherdevices['Control-Lights'] == 'On' and
        date.hour >= 7 and date.hour <= 23) then
        commandArray['Group:Schakel-alle-lampen'] = 'Off'

end
return commandArray

Re: Only one sensor activate the script

Posted: Tuesday 15 November 2016 9:09
by emme
name labels are case sensitive....
Are you sure they're written correctly?

and more...
Devicechanged trigger the script after ANY device changes its state... could ibe that during the test you trigger first the MotionSensor and then the MotionSensor voor?
in this case the script will trigger twice :P

Re: Only one sensor activate the script

Posted: Tuesday 15 November 2016 11:12
by marigo
The name labels are correct.

I have changed the first statement

Code: Select all

if ((date.hour >= 7 and date.hour <= 23) and
        (devicechanged['MotionSensor'] == 'On' or
        devicechanged['MotionSensor voor'] == 'On'))
into

Code: Select all

if (date.hour >= 7 and date.hour <= 23) and
        (devicechanged['MotionSensor'] == 'On' or
        devicechanged['MotionSensor voor'] == 'On')
And it look likes it's working now. I can trigger one of the sensors and lights will go on.
Now there are two separate statements instead of one.

Still can't explain, it should work also with one statement.