I can do this fine on motion but then the next day when i turn it on, it will come on at 15% when manually turned on. Is there a way to reset to 100% keeping the light off?
I realise i could set it back to 100 before turning off but sometimes i sit at the other end of the room (out of sight of the motion) so dont really want it flashing up to 100 and then off.
potential fix ?
commandArray['Kitchen Lights']='Set Level 100'
commandArray['Kitchen Lights']='Off'
Code: Select all
-- script_kitchen_Lights.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 ((time.hour >= 23 or time.hour <= 5 and devicechanged['Kitchen Motion'] == 'On') and uservariables["Kitchen_Lights"] == 0 and (otherdevices['Sunset'] == 'On' or tonumber(otherdevices_svalues['Kitchen Light Level']) < 5)) then
print("Setting Kitchen Lights to 15%")
-- commandArray['Kitchen Lights']='On'
commandArray['Kitchen Lights']='Set Level 15'
commandArray['Variable:Kitchen_Lights'] = '1'
elseif (uservariables["Kitchen_Lights"] == 1 and otherdevices['Kitchen Motion'] == 'Off' and timedifference(otherdevices_lastupdate['Kitchen Motion']) > 90 and otherdevices['Kitchen Lights'] ~='Off') then
commandArray['Kitchen Lights']='Off'
commandArray['Variable:Kitchen_Lights'] = '0'
end