Set Home/Away Hub Status


#1

Hi. I currently use a simulated switch to set my hub’s status to home or away, the switch is controlled by my phone presence but also depends on a boolean that is changed when someone presses a specific button at home (for people I don’t want to force to install apps tracking their location).
I had this running on Stringify and now I moved it to webCoRE, so I’d like to know if there is a more direct way of controlling the hub’s home/away status that doesn’t require a simulated switch.
Thanks :slight_smile:


#2

You can control it directly through WebCore. Just use something like this:

if button is pressed
  someoneIsHome = !someoneIsHome
endif
if phone presence changes to present
     or
   someoneIsHome is true
then
  set location mode to home
else
  set location mode to away
endif

Note: Define someoneIsHome as boolean in the define section.

Not sure how familiar you are with programming. Try to create this and if you have trouble, let us know There is usually someone around to help.


#3

Great, thanks. My brothers taught me to program Perl when I was 7-8 years old, and now I’m incursioning in programming again with home control tasks. I started using Stringify some weeks ago but I loved the potential of webCoRE so much more that I’m spending some time trying to set up my pistons :slight_smile:

I understand how IF/ELSE works with acitionable devices like buttons or switches, but I’d like to understand more about how this works if I set a variable as a condition.
For example: if variable is 1 then turn on light else turn off
Does the ELSE turn off the light whenever the variable changes to any value that isn’t 1? Does it only operate when the variable was 1 and then is another number?

Also, why would I use variable conditions instead of triggers? I want something to happen each time a variable becomes true, should I use it as a trigger? What is the difference when using it as a condition?

I understand the use as a condition if it is set like: when I press this button, if the variable is 0, then (…).

Thanks,
Rodrigo


#4

You need to read this thread on triggers vs conditions. Basically, if you check if a variable IS 1, that is a condition and will not trigger a piston to run. Other wise, it would be running continuously as long as it stayed 1. Instead, you look for it changing to 1 and that will run the piston. The interesting behavior is the else. Once you look for the variable changing to 1, the piston will actually trigger every time the variable changes. If it changes to 1, the then is executed. If it changes to anything else, the else will be executed. Make sense? In general, you need to be careful with else but it can be very powerful.


#5

Yep, makes a lot of sense, thanks!


#6

I’m having a problem with this piston.
If I’m home (my phone’s location is PRESENT) and the switch is turned off, then the location mode is set to Away. I would like the location mode to stay at “Home” and only turn to Away when the switch is off and I’m not at home.

Lines 17 to 25 are the ones that matter, the other part are some actions based on the “someoneishome” switch.


#7

My general advice is to never use ELSE statements unless there is only a single condition. With your double logic (line 18 & 20), when either one of them is false, it will fall back on the ELSE.

In other words make one block for setting it to “Home”, and another block for setting it to “Away”, and drop the ELSE entirely


#8

Thanks. I had something like that before but wanted to try this method that looked simpler. I’ll go back to that then!


#9

I’m having a hard time with this.

I used to have another piston that was working, but I wanted to simplify it so I did two things: I tried changing its “shape” to something simpler and
I was using variables and I changed it to a switch on/off status because I wanted to control it easily from the app. I was hoping that the on/off state of a switch works in a similar way to boolean variables.

I now tried two different ways and it’s always failing.

First I created four statements:
If phone location changes to present > set mode home
If switch changes to on > set mode home
If phone location changes to not present > if switch is off > set mode away
If switch changes to off > if phone location is away > set mode off

I tested it and it didn’t work. I cannot make my phone location turn “not present” (tried with fakegps, it’s not working, don’t know why) so I’m just testing the switch part: Turning the switch ON sets mode HOME and OFF sets mode AWAY, even though the phone’s location shows as PRESENT.

So I tried changing it to TWO statements:

IF Phone changes to PRESENT > set mode HOME
ELSE > IF Switch is OFF > set mode AWAY

IF Switch turns ON > set mode HOME
ELSE > IF Phone is NOT PRESENT > set mode AWAY

I then tried changing both devices to switches, to test more easily, and it only sets my home AWAY and never back HOME.

Important note: I’m using virtual switches created with the Virtual Device Creator in the app.
I used the Evaluation Console to test the switches and both are informing on/off correctly.

Do you think there’s any reason why changing variables for switches could cause any problems? Should I go back to variables and then set another pistons that make the variable true/false when the switch is on/off?

Can anyone recognise what is the problem here? :slight_smile: :slight_smile:

Thanks!


#10

Now I tried going back to the original piston logic. I even tried adding variables for the switch AND the phone location so I could limit the actions manually (setting the variables to true/false manually).

I deleted and re-created the button, and disabled the phone presence access from webCoRE and added it again.

I checked if any other pistons were interfering. This is the only (enabled) piston that references this switch, the phone’s location, these variables, and that modifies the hub’s home/away status. There are many old paused pistons, they shouldn’t interfere, right?

Every time I turn the switch off, the location changes to Away, no matter if the phone is present or (now) if the pixel variable is true.

I’m running out of ideas, any help is appreciated!

This is the current piston:

R.


#11

THIS ended up working (lines 17 to 25)


#12

temp

Just a heads-up…
If you ever leave your home with Switch 9 still on, your location will show as home. (ELSE on line 24)


#13

Yep, that’s the idea. The switch is to be enabled by other people who come to my home and I don’t want them to install the app and add as family members, etc. (mostly the cleaning lady). If someone is home and I leave, I want the hub’s status to be home until the person leaves, because when it’s set to away the blinds will close and the lighting director will start turning lights on/off randomly.

R.