Page 2 of 2

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 30 January 2020 16:16
by waaren
botany wrote: Thursday 30 January 2020 15:39 getting a error
Try with a comma behind 'Koof Sensor'

I also edited my example that had the same error..

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 30 January 2020 16:39
by botany
2020-01-30 16:36:38.585 Status: dzVents: Error (2.4.19): .../domoticz/scripts/dzVents/generated_scripts/dzevents.lua:78: attempt to index global 'PIR' (a nil value)

if PIR.state ~= 'On' and override.state ~= 'Off' then

thats line 78


what im doing wrong.. :cry: :x

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 30 January 2020 23:39
by waaren
botany wrote: Thursday 30 January 2020 16:39 if PIR.state ~= 'On' and override.state ~= 'Off' then
thats line 78
Change this line to

Code: Select all

if item.state ~= 'On' and override.state ~= 'Off' then 

Re: Light on at different dim level depending on daytime, with auto off

Posted: Friday 31 January 2020 5:43
by botany
waaren wrote: Thursday 30 January 2020 23:39
botany wrote: Thursday 30 January 2020 16:39 if PIR.state ~= 'On' and override.state ~= 'Off' then
thats line 78
Change this line to

Code: Select all

if item.state ~= 'On' and override.state ~= 'Off' then 
Okay, wil try after work. Thanks Waaren

Re: Light on at different dim level depending on daytime, with auto off  [SOLVED]

Posted: Friday 31 January 2020 18:37
by botany
this works now.
Thanks.
(but still not the same as i use on fibaro. thinking im going keep using two system, until something comes what i got)

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 05 November 2020 12:54
by nitpicker
Sorry for bumping up and old post, but I use a version of this script (thanks!) but when this part of the script is running:

Light.dimTo(dimValue)

The light will turn on, and after that it will dim to the value that is set. Can this be changed? That it will turn on on the level that is set.

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 05 November 2020 13:08
by waaren
nitpicker wrote: Thursday 05 November 2020 12:54 When this part of the script is running: Light.dimTo(dimValue)
The light will turn on, and after that it will dim to the value that is set. Can this be changed? That it will turn on on the level that is set.
Please show your version and the log it produces. From you description I do not understand what is happening so please elaborate.

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 05 November 2020 13:29
by nitpicker
The script:

Code: Select all

return {
	on = {
		devices = {234, 236}, -- Change out PIR
	},
   
   execute = function(dz, devices)
        local Light = dz.devices('Overloop licht') -- Change out light
        local ms = dz.devices(234) -- MS Trap 1
        local ms2 = dz.devices(236) -- MS Overloop
        local luxSensor = dz.devices(192) -- MS6 Lux
   
        local dimTimeTable  = { --  [   'timeSlot'   ]  = dimValue
                                    ['at 00:01-07:00']  = 2,
                                    ['at 07:01-12:00']  = 20,
                                    ['at 12:01-19:45']  = 60,
                                    ['at 22:00-24:00']  = 2,
                              }
                              
        if ((ms.state ~= 'On' and ms2.state ~= 'On' and dz.time.matchesRule('at 22:00-19:45')) or (luxSensor.lux > 20)) then 
            Light.switchOff()
            dz.log(Light.name .. ' switched Off')
        else
            for timeSlot, dimValue in pairs (dimTimeTable) do
               if dz.time.matchesRule(timeSlot) and (luxSensor.lux < 20) then 
                    Light.dimTo(dimValue)
                    dz.log(Light.name .. ' switched On (dimlevel: ' .. dimValue .. ')')
                    return false
               end      
            end
        end     
    end
}
The log:

Code: Select all

2020-11-05 13:22:44.110 Status: dzVents: Info: Handling events for: "MS trap 1", value: "On"
2020-11-05 13:22:44.111 Status: dzVents: Info: ------ Start internal script: Lamp overloop: Device: "MS trap 1 (deCONZ)", Index: 234
2020-11-05 13:22:44.115 Status: dzVents: Info: Overloop licht switched On (dimlevel: 60)
2020-11-05 13:22:44.116 Status: dzVents: Info: ------ Finished Lamp overloop
2020-11-05 13:22:44.117 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
The script switches the Hue lamp on and then it dims to the value I want.

But at night, the value is super small, but the light is first bright and then it dims to the low value. Can the light switch on with the low value without first shining bright?

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 05 November 2020 13:44
by waaren
nitpicker wrote: Thursday 05 November 2020 13:29 The script switches the Hue lamp on and then it dims to the value I want.
But at night, the value is super small, but the light is first bright and then it dims to the low value. Can the light switch on with the low value without first shining bright?
You could try this but I am not not sure if it solves your issue.

Code: Select all

return {
	on = {
		devices = {234, 236}, -- Change out PIR
	},

   execute = function(dz, devices)
        local Light = dz.devices('Overloop licht') -- Change out light
        local ms = dz.devices(234) -- Motion Sensor Trap 1
        local ms2 = dz.devices(236) -- Motion Sensor Overloop
        local luxSensor = dz.devices(192) -- MS6 Lux

        local dimTimeTable  = { --  [   'timeSlot'   ]  = dimValue
                                    ['at 00:01-07:00']  = 2,
                                    ['at 07:01-12:00']  = 20,
                                    ['at 12:01-19:45']  = 60,
                                    ['at 22:00-24:00']  = 2,
                              }

        if ((ms.state ~= 'On' and ms2.state ~= 'On' and dz.time.matchesRule('at 22:00-19:45')) or (luxSensor.lux > 20)) then
            Light.dimTo(2)
            Light.switchOff().afterSec(1)
            dz.log(Light.name .. ' switched Off')
        else
            for timeSlot, dimValue in pairs (dimTimeTable) do
               if dz.time.matchesRule(timeSlot) and (luxSensor.lux < 20) then
                    Light.dimTo(dimValue)
                    dz.log(Light.name .. ' switched On (dimlevel: ' .. dimValue .. ')')
               end
            end
        end
    end
}

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 05 November 2020 13:50
by nitpicker
Good thinking, maybe the light bulb is indeed lightning up with the last value.

Re: Light on at different dim level depending on daytime, with auto off

Posted: Thursday 05 November 2020 15:07
by nitpicker
Because of the OR statement in the script it doesn't work as hoped. I have to find another solution... or maybe anyone else has an option?