This object is in archive! 

Virtual switch or variable?

Jan shared this question 7 years ago
Need Answer

Hello all,


I want several rules to only work when it is dark. I have a virtual weather station that tells me the sunrise/sunset. I think it might be easier if I have one rule thats driven by the weathstation, which turns either a virtual switch or sets a variable to day/night (or 0/1), depending on sunrise/sunset.


My question: What is more reliable? A virtual switch or a variable? And are variable global? Can I access them with different rules?


Last question: How do I create a virtual switch, or a variable? (I am quite new...)


Thank you very much,

Jan

Replies (6)

photo
2

I had the same problem and started with a variable. The drawback is, that after a reboot, all variables are set back to zero. So I used it with values 1 (day) and 2 (night) and checked regularly if it is zero (which means a reboot has occured). In that case I had the rule check for the time of day and set the variable back to the right value (day or night) again.


That worked fine


I than used a virtual switch with no problems but then decided to use a virtual meter, because I´m not sure how many switches I will need and I dont want to switch accidentally beween night and day. The drawback here is, that the meter is accessable from the outside which might be a security issue for you.


So all versions work but to keep the rules tidy, I think I would suggest that you use a variable because it includes a reboot warning in just one rule (I use it to send a mail to my account)

photo
1

To create a variable use the tile "Variable select" from the variable section under "Puzzle" and choose "add new"


For a virtual switch or meter you have to create a new device via devicemanager. Than, instead of z-wave or other brands use "virtual device"

photo
1

Thank you, Klaus! So I think I will go with a variable (and reboot detection).

My main goal is to be as independent as possible from Zipato server issues. Somewhere I read that a virtual switch works via http. Not sure what that means, but my home should work regardless of my internet connection.

How do you "listen" to a variable change? The attached rule, doesnt work...

7oGH4px

photo
2

I think, value changes are not detected by the when rule. So you have to use another way. One way is to use a scheduler (Planer) and check regularly (e.g. every five minutes) the state. I do something similar with my reboot check (which I use to reset the virtual meter to the right state) (attached picture)


And please keep in mind not to copy/paste Message or Scheduler blocks as they cause trouble:


https://community.zipato.com/knowledge-base/article/how-to-copy-rules-in-rule-creator

photo
1

Klaus, thank you! I decided to go for the Virtual Switch. Reason for me was the ability to use "WHEN (sensor block) Virtual Switch ANY" to trigger rules. And I can easily switch it via the app, in case the Virtual Weather Station is offline. ;-)

BTW: Do you know how I can delete variables, which aren't needed anymore?

photo
2

Normaly it should work, sometimes I had problems because the rule was only executed in some parts. I then put a 1 second delay after "switch any" and the rule worked.


Deleting a variable is possible via api, but it is a bit complicated. You have to find the rule section, use get, search for the variable, remember the id and delete it somewhere else. I haven´t done it for a while so you have to search the topics for deleting variables. Sorry, its a bit late and I had some beer ;-) If you don´t find it, I´ll be able to help you tomorrow ;-)

Leave a Comment
 
Attach a file