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

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
botany
Posts: 8
Joined: Monday 27 January 2020 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: netherlands
Contact:

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

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
botany
Posts: 8
Joined: Monday 27 January 2020 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: netherlands
Contact:

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

Post 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
botany
Posts: 8
Joined: Monday 27 January 2020 20:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: netherlands
Contact:

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

Post 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)
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

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

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

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

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

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

Post by nitpicker »

Good thinking, maybe the light bulb is indeed lightning up with the last value.
nitpicker
Posts: 69
Joined: Tuesday 29 July 2014 10:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Contact:

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

Post 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?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest