[Solved with script]: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!
Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
McJohn
Posts: 26
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi
Domoticz version: 4.9700
Contact:

[Solved with script]: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by McJohn » Thursday 18 October 2018 10:59

We made a simple script in blocky to change a Variable.
But every time when the script is running, a Neo Siren (ID=1) goes on..
(Which was not mentioned into the variable or into the Blockly.)

So, we made a new blank Variable in a new Blockly script but this script would also change another Z-Wave device..

Every new Variable nummer in a Blockly would change automatically the same number of Z-Wave ID!

How is this possible?



2018-10-18 10:37:56.279 EventSystem: Event triggered: SecPanelVariable_2
2018-10-18 10:37:56.298 (Dummy) Light/Switch (SecurityOn)
2018-10-18 10:37:56.280 Error: EventSystem: Device ('Neo', ID=2) used in event 'SecPanelVariable_2' not found, make sure that it's hardware is not disabled!
Attachments
Screenshot 2018-10-18 at 10.51.50.png
Screenshot 2018-10-18 at 10.51.50.png (41.89 KiB) Viewed 238 times
Screenshot 2018-10-18 at 11.00.22.png
Screenshot 2018-10-18 at 11.00.22.png (59.86 KiB) Viewed 238 times
Screenshot 2018-10-18 at 10.51.50.png
Screenshot 2018-10-18 at 10.51.50.png (41.89 KiB) Viewed 241 times
Last edited by McJohn on Tuesday 23 October 2018 10:10, edited 1 time in total.

Nautilus
Posts: 780
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi
Domoticz version: beta
Location: Finland
Contact:

Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by Nautilus » Friday 19 October 2018 12:39

Strange indeed. But it might be related to your attempt to set a variable On and Off. I think you cannot do that. Depending on the variable type (string, int, boolean), you need to set a string, number or true/false as its status. My guess is that trying to set a the variable to On/Off (something you can only use with a switch) is mixing things up with Blockly and Domoticz...

McJohn
Posts: 26
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi
Domoticz version: 4.9700
Contact:

Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by McJohn » Sunday 21 October 2018 10:11

Nautilus wrote:
Friday 19 October 2018 12:39
But it might be related to your attempt to set a variable On and Off. I think you cannot do that. Depending on the variable type (string, int, boolean), you need to set a string, number or true/false as its status. My guess is that trying to set a the variable to On/Off (something you can only use with a switch) is mixing things up with Blockly and Domoticz...
Thanks for your feedback. You maybe right but why is it possible to set a Variable On and Off in a blocky? (True or false are not possible to choose in a blocky). Anyway, the status of the Variable changed with this blocky. We choose another higher Variable number and we have to live with an error in the log that Domoticz also want to switch another Z-Wave device which is not active. :?

Nautilus
Posts: 780
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi
Domoticz version: beta
Location: Finland
Contact:

Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by Nautilus » Monday 22 October 2018 0:11

I don't think there's any real validation in Blockly so that it would inform when the syntax is incorrect. What comes to Domoticz user variables it seems there's actually no type boolean, please see https://www.domoticz.com/wiki/User_variables for more details. As it says there, all variables are stored as string so to set the variable with Blockly, you need to use the text block.
Anyway, the status of the Variable changed with this blocky
What do you mean by this, how does it change?

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

Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by waaren » Monday 22 October 2018 0:37

McJohn wrote:
Thursday 18 October 2018 10:59
We made a simple script in blocky to change a Variable.
But every time when the script is running, a Neo Siren (ID=1) goes on..
You cannot set a domoticz variable to On or Off
If the variable is defined as type String you can set it to "On" or "Off" (or any other valid string) and if set to type integer to 0 or 1 (or any other valid integer) etc..
The domoticz variables can be type string, integer, float, date or time. There is no type boolean
In blockly trying to set a type string or integer variable to On or Off will lead to an error like

Error: EventSystem: Error updating variable "varname": Not a valid integer
2018-10-22 00:23:07.385 Error: EventSystem: Device no. '56' used in event event_name' no longer exists, disabling event!

where 56 is the variable ID; could well be that this leads to unexpected results elsewhere in domoticz
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

McJohn
Posts: 26
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi
Domoticz version: 4.9700
Contact:

Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by McJohn » Monday 22 October 2018 20:30

Thanks gentlemen for your both explanation.
It's strange that there is the possibility in Domoticz to change a Variable in a Blocky but actually it's forbidden because it give errors..
Anyway, why does we need to change this Variable?
Because "Waaren" made us this perfect script below to set the Domotics Alarm panel On and Off with a one-button key fob.
Works perfect!

But the only problem now is that when the Security is set Armed away or disarmed with the build-in security panel of Domoticz, the Variable (which is needed for there Keyfob...) didn't change. So, when the Security is Armed with the build in panel of Domoticz and has to be disarmed with the keyfob, nothing happened...

When you guys could change the script or have a script instead of our Blockly we not may use ;) , that would be grateful!

Thanks in advance!

Screen Shot 2018-10-22 at 20.15.42.png
Screen Shot 2018-10-22 at 20.15.42.png (140.94 KiB) Viewed 147 times


-- Alarm

return {
on = { devices = { "Keyfob" }},

logging = { level = domoticz.LOG_DEBUG,
marker = "Alarm" },

execute = function(dz, item )

local KeyfobState = item.state
local alarmVar = dz.variables("Alarm")
local securitySwitch = dz.devices("SecurityOn")
local securityPanel = dz.devices(1)

dz.log(item.name .. ", state: " .. item.state,dz.LOG_DEBUG)

if KeyfobState == "On" and alarmVar.value == "On" then
securityPanel.disarm().checkFirst()
securitySwitch.switchOff().checkFirst().silent()
alarmVar.set("Off").silent()
elseif KeyfobState == "On" then
securityPanel.armAway().checkFirst()
securitySwitch.switchOn().checkFirst().silent()
alarmVar.set("On").silent()
end
end
}

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

Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by waaren » Tuesday 23 October 2018 0:20

McJohn wrote:
Monday 22 October 2018 20:30
....But the only problem now is that when the Security is set Armed away or disarmed with the build-in security panel of Domoticz, the Variable (which is needed for there Keyfob...) didn't change. So, when the Security is Armed with the build in panel of Domoticz and has to be disarmed with the keyfob, nothing happened...
When you guys could change the script or have a script instead of our Blockly we not may use ;) , that would be grateful!
The updated script now also triggers on the panel itself when controlled from outside this script and set the var and dummy switch accordingly.

Code: Select all

-- Alarm

local securityPanelIDX = 1                     -- device idx of your security panel
local KeyfobName       = "Keyfob"          -- device name of your Key fob

return { 
        on      =   {   devices   = { KeyfobName , securityPanelIDX }},
                        
        logging =   {   level       =   domoticz.LOG_DEBUG,
                        marker      =   "Alarm" },
    
    execute = function(dz, item )
        
        local KeyfobState    = dz.devices(KeyfobName).state
        local alarmVar       = dz.variables("Alarm")
        local securitySwitch = dz.devices("SecurityOn")
        local securityPanel  = dz.devices(securityPanelIDX)
        
        
        local function signalAlarmPanelState(armed)
            dz.log(item.name .. ", state: " .. item.state .. "; Setting var and switch to " .. armed ,dz.LOG_DEBUG)
            alarmVar.set(armed).silent()  
            securitySwitch.setState(armed).checkFirst().silent()                
        end

        if item.idx == securityPanel.idx then                    -- triggered by panel
            if securityPanel.state == "Disarmed" then signalAlarmPanelState("Off")
            else signalAlarmPanelState("On") 
            end
            return
        end
        
        dz.log(item.name .. ", state: " .. item.state,dz.LOG_DEBUG)
        
        if KeyfobState == "On" and alarmVar.value == "On"  then
            securityPanel.disarm().checkFirst().silent()
            signalAlarmPanelState("Off")
        elseif KeyfobState == "On"  then
            securityPanel.armAway().checkFirst().silent()
            signalAlarmPanelState("On")
        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

McJohn
Posts: 26
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi
Domoticz version: 4.9700
Contact:

[Solved] Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by McJohn » Tuesday 23 October 2018 10:07

Thank you very much my friend, it's working perfectly!
Case closed! :D

Nautilus
Posts: 780
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi
Domoticz version: beta
Location: Finland
Contact:

Re: [Solved] Re: Bug: Variable in Blockly would change automatically another Z-Wave device which is not in the Blockly

Post by Nautilus » Thursday 25 October 2018 12:45

McJohn wrote:
Tuesday 23 October 2018 10:07
Thank you very much my friend, it's working perfectly!
Case closed! :D
Good that it is working now! :)

But I think there was a slight misunderstanding earlier:
It's strange that there is the possibility in Domoticz to change a Variable in a Blocky but actually it's forbidden because it give errors..
We did not mean that you couldn't change a variable with Blocky - because you definitely can! :)
But you cannot use a device state (On/Off) for this, you need to use a text block. The string in the text block can then be "On", "Off", "True", "False" or whatever you need it to be. Hope this helps for your future event needs...:)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests