Switch off, then hold up for 2 hours  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Switch off, then hold up for 2 hours

Post by Larsoss »

Hi, I am using this script to make the lights in my group turn on automatically, works perfectly. However, there is 1 light (switch) in the group that we often turn off. Now of course I can take it out of my group, but then it NEVER turns on.

Now I actually want to make sure that if this lamp is turned off manually, it may not switch on for the first 2/3 hours, because the group is switched by of the lux sensor, it does not turn on.

Code: Select all

-- Woonkamer verlichting automatisch schakelen. 

return {
            on      =   {   timer =   { "at 06:50-21:59 on mon, tue, wed, thu, fri" } },
       
    execute = function(dz)
        lowerLux        = 10 -- Onder welke niveau moet het script starten.
        upperLux        = 50 -- Geen idee 
        currentLux      = dz.devices(46).lux       --Hier zet je de naam/IDX van je sensor in.
        outsideLights   = dz.groups("Woonkamer")   --Hier vernoem je de groep die aan moet.
        
        if currentLux < lowerLux then
            outsideLights.switchOn().checkFirst()
        elseif currentLux > upperLux then
            outsideLights.switchOff().checkFirst()
        end
    end
}
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by waaren »

Larsoss wrote: Tuesday 18 August 2020 16:26 Hi, I am using this script to make the lights in my group turn on automatically, works perfectly. However, there is 1 light (switch) in the group that we often turn off. Now of course I can take it out of my group, but then it NEVER turns on.

Now I actually want to make sure that if this lamp is turned off manually, it may not switch on for the first 2/3 hours, because the group is switched by of the lux sensor, it does not turn on.
I guess the only way to do this is by taking the special light it out the group and control it as a separate light in dzVents.

Can you try this?

Code: Select all

-- Woonkamer verlichting automatisch schakelen.

local specialLight = 'name of your special light'

return
{
    on =
    {
        timer =
        {
            "at 06:50-21:59 on mon, tue, wed, thu, fri"
        },
        devices =
        {
            specialLight, 
        },
    },

    data =
    {
        lightOff =
        {
            initial = 0,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = groupLights,
    },

    execute = function(dz, item)

        lowerLux        = 10 -- Onder welke niveau moet het script starten.
        upperLux        = 50 -- Geen idee
        currentLux      = dz.devices(46).lux       --Hier zet je de naam/IDX van je sensor in.
        outsideLights   = dz.groups("Woonkamer")   --Hier vernoem je de groep die aan moet.
        specialLight     = dz.devices(specialLight)

        if item.isDevice then
            if item.state == 'Off' then
                dz.data.lightOff = os.time()
            end
            return
        end

        if currentLux < lowerLux then
            outsideLights.switchOn().checkFirst()
            if dz.data.lightOff < ( os.time() - 7200 ) then specialLight.switchOn().checkFirst().silent() end
        elseif currentLux > upperLux then
            outsideLights.switchOff().checkFirst()
            specialLight.switchOff().checkFirst().silent()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

Unfortunately, it springs back on.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by waaren »

Larsoss wrote: Tuesday 18 August 2020 17:48 Unfortunately, it springs back on.
Did you take it out of the group and tried a second time?
I assumed when you switch off the light it is done via Domoticz. Is that assumption valid?

If still not OK then please share the log of the script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

waaren wrote: Tuesday 18 August 2020 18:07
Larsoss wrote: Tuesday 18 August 2020 17:48 Unfortunately, it springs back on.
Did you take it out of the group and tried a second time?
I assumed when you switch off the light it is done via Domoticz. Is that assumption valid?

If still not OK then please share the log of the script.

No I had not removed it, I have now. He does not jump on now, and the other 2 do. See the logging


Code: Select all

 Status: dzVents: Info: ------ Start internal script: Script #2test:, trigger: "every 2 minutes on mon, tue, wed, thu, fri between 06:50 and 21:59 "
2020-08-18 19:16:00.475 Status: dzVents: Debug: Processing device-adapter for Lux Hue Woonkamer: Lux device adapter
2020-08-18 19:16:00.476 Status: dzVents: Debug: Processing device-adapter for Woonkamer: Group device adapter
2020-08-18 19:16:00.478 Status: dzVents: Debug: Processing device-adapter for Tasmota-Lamp_naast_kast: Switch device adapter
2020-08-18 19:16:00.478 Status: dzVents: Debug: Constructed timed-command: On
2020-08-18 19:16:00.478 Status: dzVents: Debug: Constructed timed-command: On
2020-08-18 19:16:00.480 Status: dzVents: Info: ------ Finished Script #2test
2020-08-18 19:16:00.480 Status: dzVents: Info: -=# P1 Toon #=-: ------ Start internal script: Toon_script:, trigger: "every minute"
2020-08-18 19:16:00.878 Status: dzVents: Info: -=# P1 Toon #=-: ------ Finished Toon_script
2020-08-18 19:16:00.880 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-08-18 19:16:01.028 (Dummy) Light/Switch (Automatisch Licht Woonkamer)
2020-08-18 19:16:01.974 (MQTT Discovery) onCommand 002/Tasmota-Vitrine: Command: 'On', Level: 0, Color:
2020-08-18 19:16:01.975 (MQTT Discovery) MqttClient::Publish cmnd/Vitrine/POWER (ON)
2020-08-18 19:16:02.023 (Hue) Color Switch (Woonkamerlamp)
2020-08-18 19:16:02.187 (MQTT Discovery) 002/Tasmota-Vitrine: Topic: 'tele/Vitrine/STATE 'Setting nValue: 0->1, sValue: ''->''
2020-08-18 19:16:12.218 (MQTT Discovery) 001/Tasmota-Lamp_naast_kast: Topic: 'tele/Lamp_naast_kast/STATE 'Setting nValue: 0->0, sValue: ''->''
2020-08-18 19:16:12.485 Status: dzVents: Info: Handling events for: "Tasmota-Lamp_naast_kast", value: "Off"
2020-08-18 19:16:12.485 Status: dzVents: Info: ------ Start internal script: Script #2test: Device: "Tasmota-Lamp_naast_kast (MQTT Discovery)", Index: 123
2020-08-18 19:16:12.488 Status: dzVents: Debug: Processing device-adapter for Lux Hue Woonkamer: Lux device adapter
2020-08-18 19:16:12.489 Status: dzVents: Debug: Processing device-adapter for Woonkamer: Group device adapter
2020-08-18 19:16:12.491 Status: dzVents: Info: ------ Finished Script #2test
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

Still not working Waaren. Do you have other options?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by waaren »

Larsoss wrote: Monday 24 August 2020 12:22 Still not working Waaren. Do you have other options?
I understood form your previous post that it did not switched On after you removed it from the group.

Can you please explain what the current situation is and what does work and what does not work?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

When i use you're script, and removed the lamp naast kast out of my group.. it won't turn on when the script is running.

So my other 2 device's from my group turn on, but not the special light.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by waaren »

Larsoss wrote: Monday 24 August 2020 13:27 When i use you're script, and removed the lamp naast kast out of my group.. it won't turn on when the script is running.

So my other 2 device's from my group turn on, but not the special light.
The special light will not turn on for 7200 seconds when it's switched off by something else then the script.
It is my understanding that you asked for that.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

Almost correct.

I want all 3 lights to go on, so my group + special light, but if I turn the lamp off manually afterwards, I want it to stay off.

For example: in the evening we watch TV, but after a while the lamps switch on (automatically), the lamp next to the cupboard is quite bright (not dimmable) so we often switch it off afterwards.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by waaren »

Larsoss wrote: Monday 24 August 2020 13:56 Almost correct.

I want all 3 lights to go on, so my group + special light, but if I turn the lamp off manually afterwards, I want it to stay off.

For example: in the evening we watch TV, but after a while the lamps switch on (automatically), the lamp next to the cupboard is quite bright (not dimmable) so we often switch it off afterwards.
That is what the script is supposed to do. Once it is switched off manually, it will not be switched On by the script for the next 7200 seconds.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Switch off, then hold up for 2 hours

Post by rrozema »

You're trying to fix the wrong problem. You're trying to keep the light off, whereas you better should avoid that it gets switched on.

One trick I apply often is to create a dummy switch and have a script react to the state of that switch instead of to a timer. Timers are hard to program: they fire every minute again and when they fire, you still need to check for all your conditions. Here is a script I use to switch one or more outside lights. They go on when the evening starts and off when I go to sleep. Because the script uses 2 dummy switches: "Time for Avond" and "slaaptijd" the lights are only switched when either of those switches changes state. If you choose to switch a light off after it was switched on, it will remain off until the next day (or someone switches it on). And also, when it gets dark after I go to sleep, the lights will not go on at all. Plus, it is easy to test your script because all you need to do is click the dummy switch and the script will think it just got dark, or you just went to sleep. And also, it is easy to re-use the same dummy switches in other scripts as well. Think of all the other things you can do when Domoticz knows when it gets dark or when you go to sleep. :-)

All you need to do to use this script is: create two dummy switches:
1 - 'Time for Avond' and
2 - 'Slaaptijd'.
You can of course call them whatever you want, just change the names in the script too.

You can use timers to change state of either or both of the dummy switches, or you can use another script. For example, you could create a script to have 'Time for Avond' switch on and off by some sensor's lux level. Any way, next time when you decide to change something, you won't have to go through all of your scripts anymore: all of your scripts react to the dummy switch, and they don't know about the actual conditions when it goes off or on.

Code: Select all

-- This script can be used to control garden or porch lights: These 
-- lights should go on when it gets dark and off when the sun comes 
-- up. But, if you're anything like me, you think it's a waste to 
-- leave them on when nobody's there to see them anyway. So you want 
-- them to go off while you're asleep. This sounds simple, but your 
-- sleep time may vary, plus the time the sun sets and rises varies 
-- throughout the year. So much even that in some periods the sun does
-- not set before you go to sleep or it is up already before you wake
-- up, in both situations the lights never need to switch on. This 
-- simple script accomplishes this task with ease. Plus it makes it
-- easy to adapt the timers to you personal life style.
-- 
-- How does it work? 1st you create 2 dummy On/Off switches. The names 
-- of these switches you later put in the settings below this comment. 
-- On one of the switches you define 2 timers:
--  1 - On at 30 minutes before sunset
--  2 - Off at 30 minutes after sunrise
-- On the other switch you define 4 timers:
--  1 - On at 23:00 on work days
--  2 - Off at 7:00 on work days
--  3 - On at 0:00 on weekend days
--  4 - Off at 9:00 on weekend days
-- Of course you can vary the timers on the 2nd switch depending on 
-- your personal life style.
-- Now you paste this script code into a DzVents script, fill in the 
-- names of the both dummy switches you created. And you fill in the 
-- names of the lights you want to switch. If you want to switch more 
-- than one light, simply enter multiple names, separate them with a
-- comma. Then give your script a name and click the Save button.
-- To see if it works, you don't need to wait for the evening, you 
-- can simply push the buttons yourself :-). This is also a nice way
-- to override the timers if you're one day expecting someone to 
-- arrive late or early.

-- Instead of using a timer for the darkness switch, you can also opt 
-- to use a lux meter to actually measure darkness and feed this into 
-- the script. I don't have an outdoor lux sensor, so I leave that to 
-- your own imagination.


-- Specify the name of the 1st dummy switch here.
local DARK_TIMER_NAME = 'Time for Avond'

-- Specify the name of the 2nd dummy switch here.
local SLEEP_TIMER_NAME = 'Slaaptijd'

-- Specify the names of the switches for your garden or porch lights
-- here. If you want to switch multiple lights specify them like
-- { 'light1', 'light2', 'light3' }
local BUITENLAMPEN = { 'Hal: Buitenlamp' }

return {
	on = {
		devices = {
			DARK_TIMER_NAME,
			SLEEP_TIMER_NAME
		}
	},
	execute = function(domoticz, device)
	    domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	    
	    if device.isDevice and (DARK_TIMER_NAME == device.name or SLEEP_TIMER_NAME == device.name) then
            local dark = domoticz.devices(DARK_TIMER_NAME)
            local sleep = domoticz.devices(SLEEP_TIMER_NAME)

    	    if nil == dark then
    	        domoticz.log( "Missing device " .. DARK_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    elseif nil == sleep then
    	        domoticz.log( "Missing device " .. SLEEP_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    else
    	        domoticz.devices().filter(BUITENLAMPEN).forEach(
    	            function(lamp)
            		    if dark.bState and not sleep.bState then
            		        if not lamp.bState then
            		            lamp.switchOn()
            		        end
                        else
                            if lamp.bState then
                	            lamp.switchOff()
                	        end
                        end
    	            end
	            )
	        end
	    end
	end
}
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

rrozema wrote: Monday 24 August 2020 15:01 You're trying to fix the wrong problem. You're trying to keep the light off, whereas you better should avoid that it gets switched on.

One trick I apply often is to create a dummy switch and have a script react to the state of that switch instead of to a timer. Timers are hard to program: they fire every minute again and when they fire, you still need to check for all your conditions. Here is a script I use to switch one or more outside lights. They go on when the evening starts and off when I go to sleep. Because the script uses 2 dummy switches: "Time for Avond" and "slaaptijd" the lights are only switched when either of those switches changes state. If you choose to switch a light off after it was switched on, it will remain off until the next day (or someone switches it on). And also, when it gets dark after I go to sleep, the lights will not go on at all. Plus, it is easy to test your script because all you need to do is click the dummy switch and the script will think it just got dark, or you just went to sleep. And also, it is easy to re-use the same dummy switches in other scripts as well. Think of all the other things you can do when Domoticz knows when it gets dark or when you go to sleep. :-)

All you need to do to use this script is: create two dummy switches:
1 - 'Time for Avond' and
2 - 'Slaaptijd'.
You can of course call them whatever you want, just change the names in the script too.

You can use timers to change state of either or both of the dummy switches, or you can use another script. For example, you could create a script to have 'Time for Avond' switch on and off by some sensor's lux level. Any way, next time when you decide to change something, you won't have to go through all of your scripts anymore: all of your scripts react to the dummy switch, and they don't know about the actual conditions when it goes off or on.

Code: Select all

-- This script can be used to control garden or porch lights: These 
-- lights should go on when it gets dark and off when the sun comes 
-- up. But, if you're anything like me, you think it's a waste to 
-- leave them on when nobody's there to see them anyway. So you want 
-- them to go off while you're asleep. This sounds simple, but your 
-- sleep time may vary, plus the time the sun sets and rises varies 
-- throughout the year. So much even that in some periods the sun does
-- not set before you go to sleep or it is up already before you wake
-- up, in both situations the lights never need to switch on. This 
-- simple script accomplishes this task with ease. Plus it makes it
-- easy to adapt the timers to you personal life style.
-- 
-- How does it work? 1st you create 2 dummy On/Off switches. The names 
-- of these switches you later put in the settings below this comment. 
-- On one of the switches you define 2 timers:
--  1 - On at 30 minutes before sunset
--  2 - Off at 30 minutes after sunrise
-- On the other switch you define 4 timers:
--  1 - On at 23:00 on work days
--  2 - Off at 7:00 on work days
--  3 - On at 0:00 on weekend days
--  4 - Off at 9:00 on weekend days
-- Of course you can vary the timers on the 2nd switch depending on 
-- your personal life style.
-- Now you paste this script code into a DzVents script, fill in the 
-- names of the both dummy switches you created. And you fill in the 
-- names of the lights you want to switch. If you want to switch more 
-- than one light, simply enter multiple names, separate them with a
-- comma. Then give your script a name and click the Save button.
-- To see if it works, you don't need to wait for the evening, you 
-- can simply push the buttons yourself :-). This is also a nice way
-- to override the timers if you're one day expecting someone to 
-- arrive late or early.

-- Instead of using a timer for the darkness switch, you can also opt 
-- to use a lux meter to actually measure darkness and feed this into 
-- the script. I don't have an outdoor lux sensor, so I leave that to 
-- your own imagination.


-- Specify the name of the 1st dummy switch here.
local DARK_TIMER_NAME = 'Time for Avond'

-- Specify the name of the 2nd dummy switch here.
local SLEEP_TIMER_NAME = 'Slaaptijd'

-- Specify the names of the switches for your garden or porch lights
-- here. If you want to switch multiple lights specify them like
-- { 'light1', 'light2', 'light3' }
local BUITENLAMPEN = { 'Hal: Buitenlamp' }

return {
	on = {
		devices = {
			DARK_TIMER_NAME,
			SLEEP_TIMER_NAME
		}
	},
	execute = function(domoticz, device)
	    domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	    
	    if device.isDevice and (DARK_TIMER_NAME == device.name or SLEEP_TIMER_NAME == device.name) then
            local dark = domoticz.devices(DARK_TIMER_NAME)
            local sleep = domoticz.devices(SLEEP_TIMER_NAME)

    	    if nil == dark then
    	        domoticz.log( "Missing device " .. DARK_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    elseif nil == sleep then
    	        domoticz.log( "Missing device " .. SLEEP_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    else
    	        domoticz.devices().filter(BUITENLAMPEN).forEach(
    	            function(lamp)
            		    if dark.bState and not sleep.bState then
            		        if not lamp.bState then
            		            lamp.switchOn()
            		        end
                        else
                            if lamp.bState then
                	            lamp.switchOff()
                	        end
                        end
    	            end
	            )
	        end
	    end
	end
}
Neat, this works well for me.

You do write that it is also possible with the lux switch, which is great. Where should I place it then? Because don't understand everything so well about Scripts ..

I also tried not to add all lamps separately, but that my group is switched. This didn't work. Unfortunately, because that would be even better. Especially when more lamps are added later.

Code: Select all

-- Specify the name of the 1st dummy switch here.
local DARK_TIMER_NAME = 144

-- Specify the name of the 2nd dummy switch here.
local SLEEP_TIMER_NAME = 145

-- Specify the names of the switches for your garden or porch lights
-- here. If you want to switch multiple lights specify them like
-- { 'light1', 'light2', 'light3' }
local BUITENLAMPEN = { 'Tasmota-Vitrine', 'Tasmota-Lamp_naast_kast', 'Woonkamerlamp' }

return {
	on = {
		devices = {
			DARK_TIMER_NAME,
			SLEEP_TIMER_NAME
		}
	},
	execute = function(domoticz, device)
	    domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	    
	    if device.isDevice and (DARK_TIMER_NAME == device.name or SLEEP_TIMER_NAME == device.name) then
            local dark = domoticz.devices(DARK_TIMER_NAME)
            local sleep = domoticz.devices(SLEEP_TIMER_NAME)

    	    if nil == dark then
    	        domoticz.log( "Missing device " .. DARK_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    elseif nil == sleep then
    	        domoticz.log( "Missing device " .. SLEEP_TIMER_NAME .. ".", domoticz.LOG_ERROR)
    	    else
    	        domoticz.devices().filter(BUITENLAMPEN).forEach(
    	            function(lamp)
            		    if dark.bState and not sleep.bState then
            		        if not lamp.bState then
            		            lamp.switchOn()
            		        end
                        else
                            if lamp.bState then
                	            lamp.switchOff()
                	        end
                        end
    	            end
	            )
	        end
	    end
	end
}
I had tried to change this in group but that didn't work, there is a nice solution for that?

Code: Select all

local BUITENLAMPEN = dz.groups("Woonkamer")
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Switch off, then hold up for 2 hours  [Solved]

Post by rrozema »

The code isn't written for groups. Just specify multiple device names as described in the comments. Using a group you can't address the individual switches as the script does.

To have the lights triggered by a lux sensor you would add a separate script, controlling one of the dummy switches. You do not add it in this script.
Something like this should do the trick, I haven't tested this and you need to adjust the device names for your specific situation of course.

Code: Select all

local LUX_SENSOR_NAME = 'My Lux Sensor'
local SWITCH_NAME = 'Time for Avond'

return {
	on = {
		devices = {
			LUX_SENSOR_NAME
		}
	},
	execute = function(domoticz, device)
	    if device.isDevice and device.name == LUX_SENSOR_NAME then
	        local switch = domoticz.devices(SWITCH_NAME)
	        
	        if switch == nil then
	            domoticz.log( "Missing device " .. SWITCH_NAME .. ".", domoticz.LOG_ERROR)
	        elseif device.lux < 100 and switch.bState ~= true then
	            switch.switchOn()
	        elseif device.lux >= 100 and switch.bState == true then
	            switch.switchOff()
	        end
	    end
	end
}
Last edited by rrozema on Tuesday 25 August 2020 0:11, edited 1 time in total.
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

rrozema wrote: Monday 24 August 2020 23:59 The code isn't written for groups. Just specify multiple device names as described in the comments. Using a group you can't address the individual switches as the script does.

To have the lights triggered by a lux sensor you would add a separate script, controlling one of the dummy switches. You do not add it in this script.
So if i use this on, what do i need to change to switch the dummy.. i think this one is almost complete.

Code: Select all


return {
            on      =   {   timer =   { "every 2 minutes" } },
       
    execute = function(dz)
        lowerLux        = 18 -- Onder welke niveau moet het script starten.
        upperLux        = 45 -- Boven de waarde gaan de lampen automatisch uit. 
        currentLux      = dz.devices(46).lux       --lux sensor
        woonkamerlampen   = dz.devices(144)   --Dummy switch day/night.
        
        if currentLux < lowerLux then
            woonkamerlampen.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
        end
    end
}



Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Switch off, then hold up for 2 hours

Post by rrozema »

sorry, first response was on my phone. I later added the example on my pc. Actually, let me improve it a little... One moment....

I was thinking of adding a data variable so that it wouldn't go on again if you had it manually turned off or on. But that makes it more complicated and as an example, simple is better.

Code: Select all

local LUX_SENSOR_NAME = 'My Lux Sensor'
local SWITCH_NAME = 'Time for Avond'

local OFF_LEVEL = 45
local ON_LEVEL = 18

return {
	on = {
		devices = {
			LUX_SENSOR_NAME
		}
	},
	execute = function(domoticz, device)
	    if device.isDevice and device.name == LUX_SENSOR_NAME then
	        local switch = domoticz.devices(SWITCH_NAME)
	        
	        if switch == nil then
	            domoticz.log( "Missing device " .. SWITCH_NAME .. ".", domoticz.LOG_ERROR)
	        elseif switch.bState == true and device.lux >= OFF_LEVEL then
	            switch.switchOff()
	        elseif switch.bState ~= true and device.lux < ON_LEVEL then
	            switch.switchOff()
	        end
	    end
	end
}
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

rrozema wrote: Tuesday 25 August 2020 0:12 sorry, first response was on my phone. I later added the example on my pc. Actually, let me improve it a little... One moment....

I was thinking of adding a data variable so that it wouldn't go on again if you had it manually turned off or on. But that makes it more complicated and as an example, simple is better.

Code: Select all

local LUX_SENSOR_NAME = 'My Lux Sensor'
local SWITCH_NAME = 'Time for Avond'

local OFF_LEVEL = 45
local ON_LEVEL = 18

return {
	on = {
		devices = {
			LUX_SENSOR_NAME
		}
	},
	execute = function(domoticz, device)
	    if device.isDevice and device.name == LUX_SENSOR_NAME then
	        local switch = domoticz.devices(SWITCH_NAME)
	        
	        if switch == nil then
	            domoticz.log( "Missing device " .. SWITCH_NAME .. ".", domoticz.LOG_ERROR)
	        elseif switch.bState == true and device.lux >= OFF_LEVEL then
	            switch.switchOff()
	        elseif switch.bState ~= true and device.lux < ON_LEVEL then
	            switch.switchOff()
	        end
	    end
	end
}
just think that I have to turn the on / off times of the sleep dummy exactly because it concerns indoor lamps?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

By the time for avond, you mean the sleep dummy I guess? With the 4 timers, of which I can remove the timers with the latest script? Because it is now switched by the script.
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Switch off, then hold up for 2 hours

Post by rrozema »

Larsoss wrote: Tuesday 25 August 2020 9:00 By the time for avond, you mean the sleep dummy I guess? With the 4 timers, of which I can remove the timers with the latest script? Because it is now switched by the script.
If you feel like a hen or a rooster you can switch the sleep-dummy by the lux script and go to sleep when the sun goes down and get up when the sun comes up :lol:. But I think -being a human- it makes more sense to have the avond-dummy switched by the lux script. The avond-dummy acts as an enabler: if avond is on, the light can go on. The sleep-dummy acts as a disabler: if the sleep dumy comes on, the lights will be off.

Correct, you should remove the timers from the dummy button when you want to have it switched by the lux script.
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Switch off, then hold up for 2 hours

Post by Larsoss »

haha. indeed I was that far already. I only tried to darken the lux sensor to test, but the dummy switch (evening) did not turn on.

Can i send you a DM?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest