Page 1 of 1

Reset Light Level without it coming on?

Posted: Tuesday 22 August 2017 12:29
by jimtrout87
I have a light in my kitchen which is only used by switch or voice control normally, so no auto turn on in the day, but i am now starting to go down at night (new baby) and between 11 pm & 6am want it to auto come on at 15%.

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

Re: Reset Light Level without it coming on?

Posted: Thursday 31 August 2017 19:38
by zicht
Hi

I noticed no reply's on your post.

Code: Select all

commandArray['Kitchen Lights']='Set Level 100'
commandArray['Kitchen Lights']='Off'
The above code probably does not get the result your looking for, as commandarray only issues the same device once in a sequence.
So make it like this to issue both commands in one commandArray

Code: Select all

 commandArray[#commandArray +1]={['Lamp']='Set Level 100'}
 commandArray[#commandArray +1]={['Lamp']='0ff'}
By my knowledge this is the only way to solve your issue in basic lua.

You could also alter your voice script you are using for the "on" command to do the "set level 100" (you say "on" and the voicecontrol does "set level 100")

or if you other (pir) script is doing a "Set level x" you could make a device script

Code: Select all

if devicechanged['lamp'] == "On" then commandArray ["lamp"] = "Set Level 100" end 
The above triggers only on the ON command not on Set Level ... So if your voice command set "On" it wil be turned to 100%

There are a couple of options as you see,
but the solution you are looking for (reset the level without doing actual switching) is not possible as far as i know.

Re: Reset Light Level without it coming on?

Posted: Friday 01 September 2017 13:26
by Ittiz
I'd probably try to make a script that detected the on command when sent by a button press at the dimmer and then set it to 100%. So when you turned it on, it would come on at 15% then a few moments later go to full brightness. I'm not sure if your switch has a way to distinguish between manual on commands and commands sent from the crontoller, so you may have to figure out a way for it to do that. Maybe a a variable or something like that.