problem with timedifference / lastupdate not switching switch

Post Reply
sion
Posts: 122
Joined: Friday 08 January 2016 13:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

problem with timedifference / lastupdate not switching switch

Post by sion » Sunday 29 April 2018 19:55

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
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.

User avatar
jvdz
Posts: 1423
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: problem with timedifference / lastupdate not switching switch

Post by jvdz » Sunday 29 April 2018 20:45

It should work fine.
What is the exact name for the device and are you sure it is unique?

Jos

sion
Posts: 122
Joined: Friday 08 January 2016 13:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: problem with timedifference / lastupdate not switching switch

Post by sion » Sunday 29 April 2018 21:05

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.
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests