Page 1 of 1

problem with timedifference / lastupdate not switching switch

Posted: Sunday 29 April 2018 19:55
by sion
Hi All.
Im have been using domoticz a long time, but new to Lua.
I am trying to get this script to turn off my lights, when there has been no movement on a sensor for a specified amount of time.

the utility lights work fine every time.

But the landing lights dont work. it doesnt even print ('Checking landing lights') in the log.
has anyone got any ideas as to why this isnt working?

is there a limit to the number of things you can use the timedifference function for in a script?

im on Version: 3.8153
Thanks,
Sion.

Code: Select all

-- script_time_Lights_out.lua

function timedifference (s)
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
 end
 
 commandArray = {}
 if  (otherdevices ['HOME_SECURED'] == 'Off') then
     

     
    
if (otherdevices ['Util_spot_1'] == 'On')  then
 print('evaluating utility room')
 if (otherdevices['utility_sensor'] == 'Off') and (timedifference(otherdevices_lastupdate['utility_sensor']) > 600)  then
         commandArray['Utility_Dummy']='Off'
         print('turning off utility lights')

   end
end
end

if (otherdevices['landing_light'] == 'On' ) then
    print ('Checking landing lights')
    if (timedifference(otherdevices_lastupdate['landing_pir']) > 900 ) then
        print ('turning off landing light')
        commandArray['landing_light']='Off'
        end
end
return commandArray

Re: problem with timedifference / lastupdate not switching switch

Posted: Sunday 29 April 2018 20:45
by jvdz
It should work fine.
What is the exact name for the device and are you sure it is unique?

Jos

Re: problem with timedifference / lastupdate not switching switch

Posted: Sunday 29 April 2018 21:05
by sion
Hi, thanks for the reply.
I have double checked the exact names etc.

I have now tried making a dummy switch, and using this instead of landing_light seems to work as expected.

Setting it back from landing_dummy to landig_light and it no longer works again.

For now I have just added a conman in the off action of the dummy switch to switch the light off.

Strange how it just won’t work with that one switch though.