[Solved] Stepp down light, before turning off ?
Posted: Sunday 12 August 2018 16:47
By searching this forum, using som bits and pices, a bit cut/paste
I usually ends up with what I want, or close ( AND learning as a bonus )...
This time it's close, just want's a little bit more... found the bases for this script here on the forum, just made some small adjustments ...
BUT ...
Any easy way to replace the "OFF" command by something like :
commandArray['Bad']='Set Level 5%' for 30 sek
THEN
commandArray['Bad']='OFF '
Just to get a warning
before it gets dark ( Light triggered by movement )
Arne Kjetil

This time it's close, just want's a little bit more... found the bases for this script here on the forum, just made some small adjustments ...
BUT ...
Any easy way to replace the "OFF" command by something like :
commandArray['Bad']='Set Level 5%' for 30 sek
THEN
commandArray['Bad']='OFF '
Just to get a warning

Arne Kjetil
Code: Select all
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 = {}
-- Set length of time light should be on for in seconds
timeon = 140
-- Calculate time since time PIR was last activated
difference = timedifference(otherdevices_lastupdate['Bevegelse_Bad'])
-- If the time since last activation was within 1 minute of time for light to stay on
if (difference > timeon and difference < (timeon + 61)) then
tempdiff = tostring(difference)
tempmessage = "Switch1 Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
print(tempmessage)
-- Switch off Switch1
commandArray['Bad'] = 'Off'
print('testing domoticz log')
end
return commandArray