Page 1 of 1

Converting Blockly to dzVents

Posted: Friday 26 January 2018 10:48
by htilburgs
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 1391 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?

Re: Converting Blockly to dzVents

Posted: Friday 26 January 2018 10:57
by emme

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

Re: Converting Blockly to dzVents

Posted: Friday 26 January 2018 11:16
by htilburgs
emme wrote: Friday 26 January 2018 10: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.

Re: Converting Blockly to dzVents

Posted: Friday 26 January 2018 12:06
by emme
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

Re: Converting Blockly to dzVents

Posted: Friday 26 January 2018 13:22
by Eoreh
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 1356 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 ?

Re: Converting Blockly to dzVents

Posted: Friday 26 January 2018 13:49
by htilburgs
Eoreh wrote: Friday 26 January 2018 13: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!

Re: Converting Blockly to dzVents

Posted: Sunday 28 January 2018 0:38
by Eoreh
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 1315 times