Converting Blockly to dzVents

Easy to use, 100% Lua-based event scripting framework.
Post Reply
User avatar
htilburgs
Posts: 509
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Converting Blockly to dzVents

Post by htilburgs » Friday 26 January 2018 11:48

I'm currently in the process of converting my Blockly scripts to dzVents.
I've a Blockly script that sends a notification when the front- or backdoor is opened, while the switch "Beveiliging" has status ON

Sensor - Blockly.png
Sensor - Blockly.png (72.1 KiB) Viewed 709 times

In dzVents I've made the following config:

Code: Select all

return {
    on = 
    {
        devices = {
            'Sensor Voordeur',
            'Sensor Achterdeur',
            'Beveiliging'
            }
    },
    execute = function(domoticz, device)
        if 
            {(device.name == 'Sensor Voordeur' and device.state == 'Open') and 
            (device.name == 'Beveiliging' and device.state == 'On')}
        then
            domoticz.notify('Beveiliging', 'De voordeur wordt geopend')
            domoticz.log('Voordeur wordt geopend!!')
        elseif
            {(device.name == 'Sensor Achterdeur' and device.state == 'Open') and 
            (device.name == 'Beveiliging' and device.state == 'On')}
        then
            domoticz.notify('Beveiliging', 'De achterdeur wordt geopend')
            domoticz.log('Achterdeur wordt geopend!!')
        end
    end
}
This works partly, but I cannot figure out what I'm doing wrong (I'm not a programmer and doing this with looking at examples)
In the Domoticz log (and also the notification) I get for both frontdoor (voordeur) as for backdoor (achterdeur) "Beveiliging: De voordeur wordt geopend"

Domoticz Log:

Code: Select all

2018-01-26 10:20:24.607 dzVents: Info: Handling events for: "Sensor Achterdeur", value: "Open"
2018-01-26 10:20:24.607 dzVents: Info: ------ Start internal script: Sensoren: Device: "Sensor Achterdeur (Aeon Labs Z-Stick GEN5)", Index: 559
2018-01-26 10:20:24.607 dzVents: Info: Voordeur wordt geopend!!
2018-01-26 10:20:24.607 dzVents: Info: ------ Finished Sensoren
2018-01-26 10:20:24.680 EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-01-26 10:20:26.113 dzVents: Info: Handling events for: "Sensor Achterdeur", value: "Closed"
2018-01-26 10:20:26.113 dzVents: Info: ------ Start internal script: Sensoren: Device: "Sensor Achterdeur (Aeon Labs Z-Stick GEN5)", Index: 559
2018-01-26 10:20:26.113 dzVents: Info: Voordeur wordt geopend!!
2018-01-26 10:20:26.113 dzVents: Info: ------ Finished Sensoren
2018-01-26 10:20:26.191 EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
Does anyone see a 'programming' error?
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3

User avatar
emme
Posts: 957
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Converting Blockly to dzVents

Post by emme » Friday 26 January 2018 11:57

Code: Select all

return {
    on = 
    {
        devices = {
            'Sensor Voordeur',
            'Sensor Achterdeur',
            'Beveiliging'
            }
    },
    execute = function(domoticz, device)
        if domoticz.devices('Sensor Voordeur').state == 'Open' and domoticz.devices('Beveiliging').state == 'On'
        then
            domoticz.notify('Beveiliging', 'De voordeur wordt geopend')
            domoticz.log('Voordeur wordt geopend!!')
        elseif domoticz.devices('Sensor Achterdeur').state == 'Open' and domoticz.devices('Beveiliging').state == 'On' then
            domoticz.notify('Beveiliging', 'De achterdeur wordt geopend')
            domoticz.log('Achterdeur wordt geopend!!')
        end
    end
}
dzVents runs once on each device change....
that means that by the time the script runs device.name has only 1 vlue (one of the 3 devices) so any if condition that requires an AND with 2 differen device.name will never came true

With this correction the script will run anytime one of the 3 devices change state... the script doest't care who, it just run
hope this would help
ciao
M
The most dangerous phrase in any language is:
"We always done this way"

User avatar
htilburgs
Posts: 509
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Converting Blockly to dzVents

Post by htilburgs » Friday 26 January 2018 12:16

emme wrote:
Friday 26 January 2018 11:57

Code: Select all

return {
    on = 
    {
        devices = {
            'Sensor Voordeur',
            'Sensor Achterdeur',
            'Beveiliging'
            }
    },
    execute = function(domoticz, device)
        if domoticz.devices('Sensor Voordeur').state == 'Open' and domoticz.devices('Beveiliging').state == 'On'
        then
            domoticz.notify('Beveiliging', 'De voordeur wordt geopend')
            domoticz.log('Voordeur wordt geopend!!')
        elseif domoticz.devices('Sensor Achterdeur').state == 'Open' and domoticz.devices('Beveiliging').state == 'On' then
            domoticz.notify('Beveiliging', 'De achterdeur wordt geopend')
            domoticz.log('Achterdeur wordt geopend!!')
        end
    end
}
dzVents runs once on each device change....
that means that by the time the script runs device.name has only 1 vlue (one of the 3 devices) so any if condition that requires an AND with 2 differen device.name will never came true

With this correction the script will run anytime one of the 3 devices change state... the script doest't care who, it just run
hope this would help
ciao
M
Thnx, that works!
So the difference is in the using of domoticz.devices instead of device.name?
If I'm correct in the device.name you refer to only 1 device and with domoticz.devices you refer to the defined array "devices=..."?
(I'm trying to learn dzVents... :) )

Now for the difficult part:
The frontdoor is open and notification is send.
Then (while the frontdoor is open) I open the backdoor. In this case I still got the message "Beveiliging: De voordeur wordt geopend" instead of the achterdeur.
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3

User avatar
emme
Posts: 957
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Converting Blockly to dzVents

Post by emme » Friday 26 January 2018 13:06

the execute = function(domoticz, device) works in this way:

domoticz contain the full table of domoticz framework... device, variables, scenes etc etc...
device contains only the device/variable/timer information that act the script (it works like a shortcut, but it inlcude some more option)

the hard part is because you trigger the script based on 3 devices, but you test only 2... so you can loose a possible state.

so.. explain exactly what behaivour you want to achieve...
I would also ask you if you can translate the messages in English (I'm much more familiar with :P :P) so I can better understand the situation and modify the script accordingly
thanks
ciao
M
The most dangerous phrase in any language is:
"We always done this way"

Eoreh
Posts: 74
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Converting Blockly to dzVents

Post by Eoreh » Friday 26 January 2018 14:22

I'm finishing (on this weekend) work on a general script that simplifies this syntax in dzVents. (for "Block" People)
Syntex to set up only on begin skrypt will be like this
eg2.png
eg2.png (12.12 KiB) Viewed 674 times

Code: Select all

plans={
{ onDevice={'Sensor Voordeur',state='On'}, where={'Beveiliging',state='On'}, notify={'Beveiliging','De voordeur wordt geopend'}, log={'Voordeur wordt geopend!!'},
{ onDevice={'Sensor Achterdeur',state='Open'}, where={'Beveiliging',state='On'}, notify={'Beveiliging','De achterdeur wordt geopend'}, log={'Achterdeur wordt geopend!!'}
}
This will be all that y have to set on at script (at the beginning).
I dont know your language but I believe that I did it well do copy&paste your name devices and text. In general, I mean ideas.
With this script You can do simple a lot of things.
Sounds interesting ?

User avatar
htilburgs
Posts: 509
Joined: Tuesday 03 November 2015 12:01
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Converting Blockly to dzVents

Post by htilburgs » Friday 26 January 2018 14:49

Eoreh wrote:
Friday 26 January 2018 14:22
I'm finishing (on this weekend) work on a general script that simplifies this syntax in dzVents. (for "Block" People)
Syntex to set up only on begin skrypt will be like this
eg2.png

Code: Select all

plans={
{ onDevice={'Sensor Voordeur',state='On'}, where={'Beveiliging',state='On'}, notify={'Beveiliging','De voordeur wordt geopend'}, log={'Voordeur wordt geopend!!'},
{ onDevice={'Sensor Achterdeur',state='Open'}, where={'Beveiliging',state='On'}, notify={'Beveiliging','De achterdeur wordt geopend'}, log={'Achterdeur wordt geopend!!'}
}
This will be all that y have to set on at script (at the beginning).
I dont know your language but I believe that I did it well do copy&paste your name devices and text. In general, I mean ideas.
With this script You can do simple a lot of things.
Sounds interesting ?
Sounds great!
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3

Eoreh
Posts: 74
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi
Domoticz version: beta
Location: Poland
Contact:

Re: Converting Blockly to dzVents

Post by Eoreh » Sunday 28 January 2018 1:38

I finish ver 1.1 (tested by friends).
You can download and read about it here viewtopic.php?f=59&t=21914
Simple egzample script.
eg5.png
eg5.png (25.55 KiB) Viewed 633 times

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest