Page 1 of 1

Blockly script for presence detection

Posted: Sunday 11 November 2018 18:17
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

Re: Blockly script for presence detection

Posted: Monday 12 November 2018 0:09
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
}

Re: Blockly script for presence detection

Posted: Friday 16 November 2018 17:03
by capman
Or try to change your blockly with
else if.JPG
else if.JPG (14.93 KiB) Viewed 1056 times