Blockly and global variables

Hi community,
is it possible to work with global variables in Blockly?
I have the following use case:
As soon as the house is left a rule starts. In this rule a timer should be started that waits 10 minutes and then executes code.
A second rule starts when the house is entered. This rule should reset this timer.
Is this possible?
Thanks and regards
Arne

You can use the same rule, and reset the timer if required.

Your rule could trigger off a Switch Item whose state is dependent on whether the house is empty or occupied.

Just to be clear, there is really not such thing as a global variable in any oH languages. When writiuung rules in text files there is a place to define a variable outside of the rules which makes that variable global to the file but not truly global.

A new feature is being added to core hopefully that will create a registry where data can be placed and shared between rules. This will be the way to share variables between rules but I don’t know if that’s been merged yet. Eventually that will become available in Blockly.

In JS Scripting there is a cache which is a simple map where data can be placed and shared between rules. That will probably go away when. the registry is merged and made available.

So for now the answer is no, but eventually it will be yes. As @hafniumzinc describes, use the same rule instead of splitting it into two rules.

Hello hafniumzinc,
thanks for response I will try it
Best regards
Arne

Hello rlkoshak,
thanks for your detailed feedback. I will try it as @hafniumzinc has described.
Best regards
Arne

The nearest that comes close to what you want is a storage of a value that can be used within a rule but not across a rule:

see Blockly Value Storage

What you can use though is a “virtual item” to store something in the first rule and retrieve in a second rule.

Hello Stefan,

sorry for late respose. The way of hafniumzinc suggested works so far.

Best regards
Arne

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.