multiple AND's in on-devices

Easy to use, 100% Lua-based event scripting framework.
Post Reply
terrorsource
Posts: 54
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

multiple AND's in on-devices

Post by terrorsource » Friday 06 July 2018 14:16

Hi,

I already read the wiki but it's not mentioned there.
How can i have multiple AND's in the on devices part?

I have a blocky i want to transform to DzVents but i'm confused, already saw the how-to video but that's not making it easier.

Part of my Blocky:
IF "Home" = ON AND "ZonOp" = OFF (ZonOp goes OFF 10min before sunset)
THEN "Lamp1" = ON Random in "1" minute
THEN "Lamp2" = ON Random in "1" minute

Below is my DzVents script so far, it's still missing a few things:
- timer: '10 minutes before sunset',
- AND, so Thuis = ON and 10 minutes before sunset

Code: Select all

return {
    on = {
        devices = {
            'Home'
        }
    },
    execute = function(domoticz, Home)
        domoticz.log(Home.state)
        
        if (Thuis.state == 'On') then
            local lamp1 = domoticz.devices('lamp1')
            lamp1.switchOn()
            local lamp2 = domoticz.devices('lamp2')
            lamp2.switchOn()
       end
    end
}
Another question, how can i make different IF ELSE statements in DzVents?
My blocky is 1 script and has multiple IFELSE for different situations (home, away etc)

User avatar
waaren
Posts: 943
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: multiple AND's in on-devices

Post by waaren » Friday 06 July 2018 17:19

terrorsource wrote:
Friday 06 July 2018 14:16
...
How can i have multiple AND's in the on devices part?
...
In the on devices part you enter the devices that will trigger the script. If you enter multiple devices in that area, the script will be triggered on every individual device state change. You can also use wildcards or device numbers but the script will still trigger on all.

example:
on = devices {'device1','device2'} }, -- script will be triggered on device1 and another time on device2
on = devices {'device*' } }, -- script will be triggered on device1 and another time on device2 and any other that starts with 'device'

If you share your blockly here it will be much easier for the other members on the forum to help you with the transformation to dzVents.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 54
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: multiple AND's in on-devices

Post by terrorsource » Friday 06 July 2018 19:03

This is my Blocky i'm using.

Image

I think i know how to use timers and triggers seperately but not combined and not with IF ELSE, just started with using DzVents.

User avatar
waaren
Posts: 943
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: multiple AND's in on-devices

Post by waaren » Saturday 07 July 2018 1:02

Can you check if this dzVents script does the same as your Blockly ?

Code: Select all

return {
    on      =       {   timer = { "at sunset","at 23:15"}}, 
                   
    execute = function(domoticz,trigger)            
        if domoticz.time.matchesRule("at 23:15") then 
            if domoticz.devices("Thuis").state == "Off" and domoticz.devices("Dressoir").state == "On" then      
                domoticz.devices("Dressoir").withinSec(60).switchOff()
                domoticz.devices("LampTV").withinSec(60).switchOff().checkFirst()
                domoticz.notify("LampeUitWeg","Lampen zijn uitgezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)  
            end
        elseif domoticz.devices("Thuis").state == "On" then
                domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
                domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
        else
            domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
            domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
            domoticz.notify("LampeAanWeg","Lampen zijn aangezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)   
        end
   end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 54
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: multiple AND's in on-devices

Post by terrorsource » Saturday 07 July 2018 20:57

waaren wrote:
Saturday 07 July 2018 1:02
Can you check if this dzVents script does the same as your Blockly ?

Code: Select all

return {
    on      =       {   timer = { "at sunset","at 23:15"}}, 
                   
    execute = function(domoticz,trigger)            
        if domoticz.time.matchesRule("at 23:15") then 
            if domoticz.devices("Thuis").state == "Off" and domoticz.devices("Dressoir").state == "On" then      
                domoticz.devices("Dressoir").withinSec(60).switchOff()
                domoticz.devices("LampTV").withinSec(60).switchOff().checkFirst()
                domoticz.notify("LampeUitWeg","Lampen zijn uitgezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)  
            end
        elseif domoticz.devices("Thuis").state == "On" then
                domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
                domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
        else
            domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
            domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
            domoticz.notify("LampeAanWeg","Lampen zijn aangezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)   
        end
   end
}
Almost :)

The "ZonOp" switch is turned off 10-minutes before sunset so there must be a 3th time based trigger, or the timer must set to "10 minutes before sunset" and the now-sunset switch must be delayed with 10minutes in the switchOn rule

User avatar
waaren
Posts: 943
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: multiple AND's in on-devices

Post by waaren » Saturday 07 July 2018 23:24

terrorsource wrote:
Saturday 07 July 2018 20:57

Almost :)

The "ZonOp" switch is turned off 10-minutes before sunset so there must be a 3th time based trigger, or the timer must set to "10 minutes before sunset" and the now-sunset switch must be delayed with 10minutes in the switchOn rule
Like this ?

Code: Select all

return {
    on      =       {   timer = { "10 minutes before sunset","at sunset","at 23:15"}}, 
                   
    execute = function(domoticz,trigger)            
        if domoticz.time.matchesRule("at 23:15") then 
            if domoticz.devices("Thuis").state == "Off" and domoticz.devices("Dressoir").state == "On" then      
                domoticz.devices("Dressoir").withinSec(60).switchOff()
                domoticz.devices("LampTV").withinSec(60).switchOff().checkFirst()
                domoticz.notify("LampeUitWeg","Lampen zijn uitgezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)  
            end
        elseif domoticz.devices("Thuis").state == "On" then
                domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
                domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
        elseif domoticz.time.matchesRule("10 minutes before sunset") then
            domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
            domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
            domoticz.notify("LampeAanWeg","Lampen zijn aangezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)   
        end
   end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 54
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: multiple AND's in on-devices

Post by terrorsource » Sunday 08 July 2018 11:20

waaren wrote:
Saturday 07 July 2018 23:24
terrorsource wrote:
Saturday 07 July 2018 20:57

Almost :)

The "ZonOp" switch is turned off 10-minutes before sunset so there must be a 3th time based trigger, or the timer must set to "10 minutes before sunset" and the now-sunset switch must be delayed with 10minutes in the switchOn rule
Like this ?

Code: Select all

return {
    on      =       {   timer = { "10 minutes before sunset","at sunset","at 23:15"}}, 
                   
    execute = function(domoticz,trigger)            
        if domoticz.time.matchesRule("at 23:15") then 
            if domoticz.devices("Thuis").state == "Off" and domoticz.devices("Dressoir").state == "On" then      
                domoticz.devices("Dressoir").withinSec(60).switchOff()
                domoticz.devices("LampTV").withinSec(60).switchOff().checkFirst()
                domoticz.notify("LampeUitWeg","Lampen zijn uitgezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)  
            end
        elseif domoticz.devices("Thuis").state == "On" then
                domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
                domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
        elseif domoticz.time.matchesRule("10 minutes before sunset") then
            domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
            domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
            domoticz.notify("LampeAanWeg","Lampen zijn aangezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)   
        end
   end
}
Created the Event so lets hope i'm not in the dark this night :)

terrorsource
Posts: 54
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: multiple AND's in on-devices

Post by terrorsource » Sunday 08 July 2018 22:23

waaren wrote:
Saturday 07 July 2018 23:24
terrorsource wrote:
Saturday 07 July 2018 20:57

Almost :)

The "ZonOp" switch is turned off 10-minutes before sunset so there must be a 3th time based trigger, or the timer must set to "10 minutes before sunset" and the now-sunset switch must be delayed with 10minutes in the switchOn rule
Like this ?

Code: Select all

return {
    on      =       {   timer = { "10 minutes before sunset","at sunset","at 23:15"}}, 
                   
    execute = function(domoticz,trigger)            
        if domoticz.time.matchesRule("at 23:15") then 
            if domoticz.devices("Thuis").state == "Off" and domoticz.devices("Dressoir").state == "On" then      
                domoticz.devices("Dressoir").withinSec(60).switchOff()
                domoticz.devices("LampTV").withinSec(60).switchOff().checkFirst()
                domoticz.notify("LampeUitWeg","Lampen zijn uitgezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)  
            end
        elseif domoticz.devices("Thuis").state == "On" then
                domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
                domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
        elseif domoticz.time.matchesRule("10 minutes before sunset") then
            domoticz.devices("Dressoir").withinSec(60).switchOn().checkFirst()
            domoticz.devices("LampTV").withinSec(60).switchOn().checkFirst()
            domoticz.notify("LampeAanWeg","Lampen zijn aangezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)   
        end
   end
}
Error in the logs:

2018-07-08 21:52:00.591 Status: dzVents: Info: ------ Start internal script: Dz_test:, trigger: 10 minutes before sunset
2018-07-08 21:52:00.631 Status: dzVents: Error (2.4.6): An error occured when calling event handler Dz_test
2018-07-08 21:52:00.632 Status: dzVents: Error (2.4.6): ...i/domoticz/scripts/dzVents/generated_scripts/Dz_test.lua:12: attempt to call field 'withinSec' (a nil value)
2018-07-08 21:52:00.632 Status: dzVents: Info: ------ Finished Dz_test
2018-07-08 21:52:01.219 Status: Schedule item started! Name: ZonOp, Type: Before Sunset, DevID: 83, Time: 2018-07-08 21:52:01
2018-07-08 21:58:05.346 Status: Incoming connection from: 127.0.0.1
2018-07-08 22:02:00.221 Status: dzVents: Info: ------ Start internal script: Dz_test:, trigger: at sunset
2018-07-08 22:02:00.261 Status: dzVents: Error (2.4.6): An error occured when calling event handler Dz_test
2018-07-08 22:02:00.261 Status: dzVents: Error (2.4.6): ...i/domoticz/scripts/dzVents/generated_scripts/Dz_test.lua:12: attempt to call field 'withinSec' (a nil value)
2018-07-08 22:02:00.261 Status: dzVents: Info: ------ Finished Dz_test

User avatar
waaren
Posts: 943
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: multiple AND's in on-devices

Post by waaren » Sunday 08 July 2018 23:22

terrorsource wrote:
Sunday 08 July 2018 22:23

Error in the logs:

2018-07-08 21:52:00.591 Status: dzVents: Info: ------ Start internal script: Dz_test:, trigger: 10 minutes before sunset
2018-07-08 21:52:00.631 Status: dzVents: Error (2.4.6): An error occured when calling event handler Dz_test
2018-07-08 21:52:00.632 Status: dzVents: Error (2.4.6): ...i/domoticz/scripts/dzVents/generated_scripts/Dz_test.lua:12: attempt to call field 'withinSec' (a nil value)
OK my mistake. withinSec(nnn) must be placed after the switchOn() / switchOff()

corrected below.

Code: Select all

return {
    on      =       {   timer = { "10 minutes before sunset","at sunset","at 23:15"}}, 
                   
    execute = function(domoticz,trigger)            
        if domoticz.time.matchesRule("at 23:15") then 
            if domoticz.devices("Thuis").state == "Off" and domoticz.devices("Dressoir").state == "On" then      
                domoticz.devices("Dressoir").switchOff().withinSec(60)
                domoticz.devices("LampTV").switchOff().checkFirst().withinSec(60)
                domoticz.notify("LampeUitWeg","Lampen zijn uitgezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)  
            end
        elseif domoticz.devices("Thuis").state == "On" then
                domoticz.devices("Dressoir").switchOn().checkFirst().withinSec(60)
                domoticz.devices("LampTV").switchOn().checkFirst().withinSec(60)
        elseif domoticz.time.matchesRule("10 minutes before sunset") then
            domoticz.devices("Dressoir").switchOn().checkFirst().withinSec(60)
            domoticz.devices("LampTV").switchOn().checkFirst().withinSec(60)
            domoticz.notify("LampeAanWeg","Lampen zijn aangezet omdat er niemand thuis is.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)   
        end
   end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 54
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: multiple AND's in on-devices

Post by terrorsource » Monday 09 July 2018 21:55

waaren wrote:
Sunday 08 July 2018 23:22
terrorsource wrote:
Sunday 08 July 2018 22:23

Error in the logs:

2018-07-08 21:52:00.591 Status: dzVents: Info: ------ Start internal script: Dz_test:, trigger: 10 minutes before sunset
2018-07-08 21:52:00.631 Status: dzVents: Error (2.4.6): An error occured when calling event handler Dz_test
2018-07-08 21:52:00.632 Status: dzVents: Error (2.4.6): ...i/domoticz/scripts/dzVents/generated_scripts/Dz_test.lua:12: attempt to call field 'withinSec' (a nil value)
OK my mistake. withinSec(nnn) must be placed after the switchOn() / switchOff()
Lights turned on! :D

2018-07-09 21:51:00.568 Status: dzVents: Info: ------ Start internal script: LampenSwitch_D:, trigger: 10 minutes before sunset
2018-07-09 21:51:00.610 Status: dzVents: Info: ------ Finished LampenSwitch_D
2018-07-09 21:51:00.818 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-07-09 21:52:01.386 Status: Schedule item started! Name: ZonOp, Type: Before Sunset, DevID: 83, Time: 2018-07-09 21:52:01

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests