Blockly script for presence detection

Moderator: leecollings

Post Reply
echeberri77
Posts: 39
Joined: Friday 09 March 2018 18:52
Target OS: Linux
Domoticz version: 3.9203
Location: Italy
Contact:

Blockly script for presence detection

Post by echeberri77 »

Hi everybody!!
I made a blocky script for presence detection but it seems not to work... Logic should be that if variable value 'MyBandSaverio' is AWAY or if variable value 'MyBandSilvia' is AWAY then Set Allarm switch to ON and MyBandPresence switch to OFF... at then contrary if variable MyBandSaverio is different than AWAY (variable is a string not a number...) or if variable MyBandSilvia is different than AWAY the set Allarm switch to OFF and MyBandPresence switch to ON.

But is it not working... Why? It is not a matter of presence script because I see the values of the variables changing correctly according to the beacons presence...

What is the problem then? See image on attach for more details!



Thanks for you help!

Xavier
Attachments
Senzanome.png
Senzanome.png (54.11 KiB) Viewed 1138 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blockly script for presence detection

Post by waaren »

echeberri77 wrote: Sunday 11 November 2018 18:17 I made a blocky script for presence detection but it seems not to work... Logic should be that if variable value 'MyBandSaverio' is AWAY or if variable value 'MyBandSilvia' is AWAY then Set Allarm switch to ON and MyBandPresence switch to OFF... at then contrary if variable MyBandSaverio is different than AWAY (variable is a string not a number...) or if variable MyBandSilvia is different than AWAY the set Allarm switch to OFF and MyBandPresence switch to ON.
But is it not working... Why? It is not a matter of presence script because I see the values of the variables changing correctly according to the beacons presence...
What is the problem then? See image on attach for more details!
I am by no means a Blockly expert but I did read a lot of posts on this forum about problems with the use of Blockly if / else constructs. I tested your Blockly and it does not work on my system either. If you split the Blockly in two separate Blockly's , they do execute as expected.
An advantage of using a dzVents script is that you can better see what is happening in the domoticz log.
See the example below on how your blockly could look like using dzVents

Code: Select all

-- setAlarm.lua

return {
    on      =   {   variables  =   { "MyBandS*" }},      -- wildcard for uservariables
                
    logging =   {   level      =   domoticz.LOG_DEBUG,   -- change to domoticz.LOG_ERROR when script perform as expected
                    marker     =   "setAlarm"    },

    execute = function(dz)
        local myBand        = dz.devices("PresenzaMyBand")
        local alarm         = dz.devices("Allarme")
        local isSilviaAway  = dz.variables("MyBandSilvia").value  == "AWAY"
        local isSaverioAway = dz.variables("MyBandSaverio").value == "AWAY"
        
        if isSaverioAway and isSilviaAway then
            myBand.switchOff()
            alarm.switchOn()
        else
            myBand.switchOn()
            alarm.switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Blockly script for presence detection

Post by capman »

Or try to change your blockly with
else if.JPG
else if.JPG (14.93 KiB) Viewed 1053 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest