light outsite 100% for 20 min when someone is coming home. [Solved]

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

Moderator: leecollings

Post Reply
klaaspiet
Posts: 34
Joined: Tuesday 09 January 2018 8:29
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Harlingen
Contact:

light outsite 100% for 20 min when someone is coming home. [Solved]

Post by klaaspiet »

Hy i want a trigger when someone is coming home (klaas or minke) = virtual switch thats is triggerd by location base ifttt on a iphone is working great.

when somewone is home and it is nighttime the light outsite must go on 100% for 20 min. after the 20 min he must go back on the state that is has before.

ik cant gat the right solution. is there some one who could help me out.

Code: Select all

 return {
    on = { 
        timer =     {   'at nighttime at 05:30 on mon, tue, wed, thu, fri',
                        'at nighttime at 07:00 on sat, sun',
                        'at sunrise', 
                        'at sunset',
                        'at 20:25',
                        'at 15 minutes before sunset',
                        'at 22:00 at nighttime on mon, tue, wed, thu, fri, sat, sun',
                        'at 23:00 at nighttime on mon, tue, wed, thu, fri, sat, sun' },
    devices =       {   'PowerOff',
                        167,
                        117,
                        185}
    },
    
	logging = {
	    level = domoticz.LOG_INFO,
	    marker = "Verlichting"  
	},
  
execute = function(domoticz, item)

local Binnen_Lampen                     =   domoticz.groups('Binnen-Lampen') --domoticz.devices('Keuken')
local Buiten_Lampen                     =   domoticz.groups('Buiten-Lampen') --domoticz.devices('Keuken')
local Harmony_off                       =   domoticz.devices(109)            --domoticz.devices('Woonkamer') 
local Lamp_Buiten_voordeur              =   domoticz.devices(184)
local Minke                             =   domoticz.devices(167)
local Klaas                             =   domoticz.devices(117)
local Lamp_Buiten_voordeur_schakelaar   =   domoticz.devices(185)

    if (item.isTimer) then
      
       if (domoticz.time.matchesRule('at 05:30')) then
            Binnen_Lampen.switchOn()
            Buiten_Lampen.switchOn()
            domoticz.log(Binnen_Lampen.name ..' groep is '.. Binnen_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
            domoticz.log(Buiten_Lampen.name ..' groep is '.. Buiten_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
        elseif (domoticz.time.matchesRule('at 08:20')) then
            Binnen_Lampen.switchOn()
            Buiten_Lampen.switchOn()
            domoticz.log(Binnen_Lampen.name ..' groep is '.. Binnen_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
            domoticz.log(Buiten_Lampen.name ..' groep is '.. Buiten_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
        elseif (domoticz.time.matchesRule('at sunrise')) then
            Binnen_Lampen.switchOff()
            Buiten_Lampen.switchOff()
            domoticz.log(Binnen_Lampen.name ..' groep is '.. Binnen_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
            domoticz.log(Buiten_Lampen.name ..' groep is '.. Buiten_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
        elseif (domoticz.time.matchesRule('at 15 minutes before sunset') and domoticz.time.matchesRule('at 00:00-22:00')) then
            Binnen_Lampen.switchOn()
            Buiten_Lampen.switchOn()
            domoticz.log(Binnen_Lampen.name ..' groep is '.. Binnen_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
            domoticz.log(Buiten_Lampen.name ..' groep is '.. Buiten_Lampen.state ..' geschakelt', domoticz.LOG_INFO)
        elseif (domoticz.time.matchesRule('at 22:00')) and (Harmony_off.state == "On") then
            Binnen_Lampen.switchOff()
            domoticz.log(Binnen_Lampen.name ..' groep is '.. Binnen_Lampen.state ..' geschakelt', domoticz.LOG_INFO) 
            domoticz.log('22 uur lampen gaan uit', domoticz.LOG_INFO)
            
         elseif (domoticz.time.matchesRule('at 23:00')) and (Harmony_off.state == "On") then
            Binnen_Lampen.switchOff()
            domoticz.log(Binnen_Lampen.name ..' groep is '.. Binnen_Lampen.state ..' geschakelt', domoticz.LOG_INFO) 
            domoticz.log('23 uur lampen gaan uit', domoticz.LOG_INFO) 
            
        elseif (domoticz.time.matchesRule('at 23:00')) then
            Buiten_Lampen.switchOff()
            domoticz.log(Buiten_Lampen.name ..' groep is '.. Buiten_Lampen.state ..' geschakelt', domoticz.LOG_INFO) 
            domoticz.log('Buiten verlichting gaat gaan uit', domoticz.LOG_INFO)   
        end
    
        
    elseif (item.isDevice) then
        
        
         if (Klaas.state == "On") and (domoticz.time.matchesRule('at daytime')) then
            
            Lamp_Buiten_voordeur.dimTo(100).forMin(1)
            domoticz.log('Buitenlamp gaat aan voor x minuten klaas komt thuis', domoticz.LOG_INFO)
        else
            domoticz.log('trigger klaas', domoticz.LOG_INFO)
        end    
        
        if Minke.state == "On" and (domoticz.time.matchesRule('at daytime')) then
            
            Lamp_Buiten_voordeur.dimTo(100).forMin(1)
            domoticz.log('Buitenlamp gaat aan voor x minuten minke komt thuis', domoticz.LOG_INFO)
        else
            domoticz.log('trigger minke', domoticz.LOG_INFO)
        end    
        
        if Harmony_off.state == "On" and  (domoticz.time.matchesRule('at 22:01-05:00')) then
            domoticz.log('tv gaat uit en lampen straks ook', domoticz.LOG_INFO)
            Binnen_Lampen.switchOff().afterMin(10)
        end
    
    end
end
}
Last edited by klaaspiet on Tuesday 24 September 2019 12:11, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by waaren »

klaaspiet wrote: Tuesday 10 September 2019 19:31 when somewone is home and it is nighttime the light outsite must go on 100% for 20 min. after the 20 min he must go back on the state that is has before.

I can't get the right solution. is there some one who could help me out.
@klaaspiet, happy to help but needs some extra info. Is my assumption correct that the isTimer part and Harmony Off part is already working as expected ?
If so would it be OK to split this script into two separate ones ? The part where you want an action based on Klaas or Minke coming home seem unrelated to the isTimer part and by combining this into one you do complicate the script. Splitting them has no real negative impact on performance / response.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
klaaspiet
Posts: 34
Joined: Tuesday 09 January 2018 8:29
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Harlingen
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by klaaspiet »

yes that is working as expected.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by waaren »

klaaspiet wrote: Tuesday 10 September 2019 20:30 yes that is working as expected.
And OK to split script in two separate ones?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
klaaspiet
Posts: 34
Joined: Tuesday 09 January 2018 8:29
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Harlingen
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by klaaspiet »

Yes if that is the best way to do this. Always ok
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by waaren »

klaaspiet wrote: Tuesday 10 September 2019 22:22 Yes if that is the best way to do this. Always ok
This one is a first go on the coming home and Harmony off part.
Please feel free to ask for clarification is something is not clear or when script is not working as expected.

Code: Select all

 return 
 {
    on = 
    { 
        devices = { 'PowerOff', 167, 117, 109 } ,
    },
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Coming home'  
    },
  
    data = {    dimLevel = { initial = 100 }},
    
    execute = function(domoticz, item)
        local Binnen_Lampen                     =   domoticz.groups('Binnen-Lampen') 
        local Harmony_off                       =   domoticz.devices(109)            
        local Lamp_Buiten_voordeur              =   domoticz.devices(184)
        local Minke                             =   domoticz.devices(167)
        local Klaas                             =   domoticz.devices(117)
        -- local Lamp_Buiten_voordeur_schakelaar   =   domoticz.devices(185)
    
        if ( item == Klaas or item == Minke ) and item.active and domoticz.time.matchesRule('at nighttime') then
            Lamp_Buiten_voordeur.dimTo(100)
            if Lamp_Buiten_voordeur.level < 100 then
                domoticz.data.dimLevel = Lamp_Buiten_voordeur.level
            end
            Lamp_Buiten_voordeur.dimTo(domoticz.data.dimLevel).afterSec(600)
            domoticz.log('Buitenlamp aan voor x minuten triggered by ' .. item.name, domoticz.LOG_DEBUG)
        elseif item == Harmony_off and item.active and domoticz.time.matchesRule('at 22:01-05:00') then
            domoticz.log('tv gaat uit en lampen straks ook', domoticz.LOG_DEBUG)
            Binnen_Lampen.switchOff().afterMin(10)
        end
    end
}
and the timer triggered one:

Code: Select all

 return 
 {
    on = 
    { 
        timer =     
        {
            'at nighttime at 05:30 on mon, tue, wed, thu, fri',
            'at nighttime at 07:00 on sat, sun',
            'at sunrise', 
            'at sunset',
            'at 20:25',
            'at 15 minutes before sunset',
            'at 22:00 at nighttime on mon, tue, wed, thu, fri, sat, sun',
            'at 23:00 at nighttime on mon, tue, wed, thu, fri, sat, sun' },
    },
    
	logging = {
	    level = domoticz.LOG_INFO,
	    marker = "Verlichting"  
	},
  
    execute = function(domoticz, item)

        local Binnen_Lampen                     =   domoticz.groups('Binnen-Lampen') --domoticz.devices('Keuken')
        local Buiten_Lampen                     =   domoticz.groups('Buiten-Lampen') --domoticz.devices('Keuken')
        local Harmony_off                       =   domoticz.devices(109)            --domoticz.devices('Woonkamer') 
        local Lamp_Buiten_voordeur              =   domoticz.devices(184)
        local Minke                             =   domoticz.devices(167)
        local Klaas                             =   domoticz.devices(117)
        local Lamp_Buiten_voordeur_schakelaar   =   domoticz.devices(185)

        local function showIt(newState)
            domoticz.log(Binnen_Lampen.name ..' groep is '.. newState ..'geschakeld', domoticz.LOG_INFO)
            domoticz.log(Buiten_Lampen.name ..' groep is '.. newState ..'geschakeld', domoticz.LOG_INFO)
        end
        
        local function allOn()
            Binnen_Lampen.switchOn()
            Buiten_Lampen.switchOn()
            showIt('aan ')
        end

        local function allOff()
            Binnen_Lampen.switchOff()
            Buiten_Lampen.switchOff()
            showIt('uit')
        end

        if domoticz.time.matchesRule('at 05:30') then
            allOn()
        elseif (domoticz.time.matchesRule('at 08:20')) then
            allOn()
        elseif (domoticz.time.matchesRule('at sunrise')) then
            allOff()
        elseif (domoticz.time.matchesRule('at 15 minutes before sunset') and domoticz.time.matchesRule('at 00:00-22:00')) then
            allOn()
        elseif (domoticz.time.matchesRule('at 22:00')) and (Harmony_off.state == "On") then
            Binnen_Lampen.switchOff()
            domoticz.log(Binnen_Lampen.name ..' groep is uitgeschakeld', domoticz.LOG_INFO) 
            domoticz.log('22 uur lampen gaan uit', domoticz.LOG_INFO)
            
         elseif (domoticz.time.matchesRule('at 23:00')) and (Harmony_off.state == "On") then
            Binnen_Lampen.switchOff()
            domoticz.log(Binnen_Lampen.name ..' groep is uit geschakeld', domoticz.LOG_INFO) 
            domoticz.log('23 uur lampen gaan uit', domoticz.LOG_INFO) 
            
        elseif (domoticz.time.matchesRule('at 23:00')) then
            Buiten_Lampen.switchOff()
            domoticz.log(Buiten_Lampen.name ..' groep is uitgeschakeld', domoticz.LOG_INFO) 
            domoticz.log('Buiten verlichting gaat uit', domoticz.LOG_INFO)   
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
klaaspiet
Posts: 34
Joined: Tuesday 09 January 2018 8:29
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Harlingen
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by klaaspiet »

hey man Thanks

i havelook en try this when i am back to home.
i think i'll have some questions when i try this

but thanks for the script
klaaspiet
Posts: 34
Joined: Tuesday 09 January 2018 8:29
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Harlingen
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by klaaspiet »

Is sure a nice script.
only have one question i cat almost everyting.
the only thing whats not going good is when i tun the light on with my switch that de light must go back to the last state.

also it is daytime.

Code: Select all

if  (item == Lamp_Buiten_voordeur and Lamp_Buiten_voordeur.level == 100) then
            if Lamp_Buiten_voordeur.level < 100 then
                domoticz.data.dimLevel = Lamp_Buiten_voordeur.level
            end
            Lamp_Buiten_voordeur.dimTo(domoticz.data.dimLevel).afterSec(10)
            domoticz.log('Buitenlamp aan voor 10 minuten triggered by ' .. item.name, domoticz.LOG_DEBUG)
        end
but when i do this like then its triggerd 2 times.

Code: Select all

2019-09-11 21:03:07.252 Status: dzVents: Info: Coming home: ------ Finished Verlichting_switch
2019-09-11 21:03:08.011 (Z-wave controller) General/kWh (kWh Meter)
2019-09-11 21:03:08.486 Status: dzVents: Info: Coming home: ------ Start internal script: Verlichting_switch: Device: "Lamp buiten voordeur (Z-wave controller)", Index: 184
2019-09-11 21:03:08.493 Status: dzVents: Debug: Coming home: Processing device-adapter for Binnen-Lampen: Group device adapter
2019-09-11 21:03:08.501 Status: dzVents: Debug: Coming home: Processing device-adapter for PowerOff: Switch device adapter
2019-09-11 21:03:08.508 Status: dzVents: Debug: Coming home: Processing device-adapter for Minke: Switch device adapter
2019-09-11 21:03:08.517 Status: dzVents: Debug: Coming home: Processing device-adapter for Klaas: Switch device adapter
2019-09-11 21:03:08.519 Status: dzVents: Debug: Coming home: Constructed timed-command: Set Level 24
2019-09-11 21:03:08.521 Status: dzVents: Debug: Coming home: Constructed timed-command: Set Level 24 AFTER 10 SECONDS
2019-09-11 21:03:08.521 Status: dzVents: Debug: Coming home: Buitenlamp aan voor 10 minuten triggered by Lamp buiten voordeur
2019-09-11 21:03:08.524 Status: dzVents: Info: Coming home: ------ Finished Verlichting_switch
2019-09-11 21:03:09.313 Status: dzVents: Info: Coming home: ------ Start internal script: Verlichting_switch: Device: "Lamp buiten voordeur (Z-wave controller)", Index: 184
2019-09-11 21:03:09.321 Status: dzVents: Debug: Coming home: Processing device-adapter for Binnen-Lampen: Group device adapter
2019-09-11 21:03:09.329 Status: dzVents: Debug: Coming home: Processing device-adapter for PowerOff: Switch device adapter
2019-09-11 21:03:09.336 Status: dzVents: Debug: Coming home: Processing device-adapter for Minke: Switch device adapter
2019-09-11 21:03:09.343 Status: dzVents: Debug: Coming home: Processing device-adapter for Klaas: Switch device adapter
2019-09-11 21:03:09.345 Status: dzVents: Debug: Coming home: Constructed timed-command: Set Level 24
2019-09-11 21:03:09.346 Status: dzVents: Debug: Coming home: Constructed timed-command: Set Level 24 AFTER 10 SECONDS
2019-09-11 21:03:09.347 Status: dzVents: Debug: Coming home: Buitenlamp aan voor 10 minuten triggered by Lamp buiten voordeur
2019-09-11 21:03:09.349 Status: dzVents: Info: Coming home: ------ Finished Verlichting_switch
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by waaren »

klaaspiet wrote: Wednesday 11 September 2019 21:03 Is sure a nice script.
only have one question i cat almost everyting.
the only thing whats not going good is when i tun the light on with my switch that de light must go back to the last state.
also it is daytime.
Can you try to add .silent() to the dimTo statements and try again ?
And please share the complete modified script if something is not working as expected. Thx.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
klaaspiet
Posts: 34
Joined: Tuesday 09 January 2018 8:29
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Harlingen
Contact:

Re: light outsite 100% for 20 min when someone is coming home.

Post by klaaspiet »

thanks mate it is working like a charm.

thx
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest