Away + Time lighting automation not working properly


#1

Hey everyone,

I’m trying to create a piston that will change the location mode to ‘Away’ upon the departure of two people. If they depart and the time is between sunset and sunrise, I also want one of the lights to turn on @ 50%.

I have the away portion working, every time without issue. However, the lighting automation seems to always trigger true once they leave, no matter what the time is. So if they leave the house at 10am, the lights turn on. I’m not quite sure what I did wrong regarding that if statement. I have attached a picture of the piston below. Any help is appreciated!


#2

Is it any different if the virtual device “date & time” on line 30 is changed to just the “time” virtual device?
Try that and give us a full log.

I don’t think line 44 is going to work. You’re using a local variable for StartingMode, but the value of that won’t be saved after the top half of the piston runs and then exits. Thus, StartingMode won’t have a value when line 42 triggers. The bulb should come on, but it’ll stay in Away mode so now the top half of the piston won’t execute when someone leaves. Try a global variable instead.


#3

In my testing, using Date and Time works just fine. So that shouldn’t be the issue.

I agree. Logs would be helpful on this one.

A global variable is only needed if you want to share information between two different pistons. There’s nothing wrong with using a local variable here.

Pistons like this one don’t “run and exit” like a script in other programming languages that you might be familiar with would do. They sit there and “hum along” waiting for the events (triggers) to happen so that they can jump into action. So a value stored in a local variable will still persist after the piston finishes a run through…(because it does not exit…it just goes back to waiting for the next Trigger).


#4

Thanks for the replies…What’s the best way to get the logs? Is there a way other than Live Logging? I only ask since due to the nature of people leaving the house, I may not be available to hit the GUI to get that. Is there anyway to save log specific to that piston somewhere? Or do I just need to leave live logging open on a machine throughout the day?


#5

Yeah, just turn Logging on the piston to Full and let it run. As events happen during the day the piston will keep a log of the things that kicked it off. You can then paste in the results of what you get so we can see what’s going on.

image


#6

re: Variables - I stand corrected.

One way I’ve found to simulate coming and going is to create simulated switches and use them in place of the presence sensors. Log into the API and create a VirtualMe and VirtualWife then replace the presence sensors in your piston with those. From the app, you can “come and go” virtually without having to leave the house and then you can watch the log.

Of course we’ll try to help you read the log, but something else that you can do is to add push notifications in your ‘then’ statements to tell you what it’s doing. It’s a debugging trick to help you visualize where you are in the logic tree.


#7

Thank you, @Mike1616. Logging set to full. I will throw the logs up as soon as it runs again.

@jsducote Good thinking! I usually do add notifications for debugging but it totally slipped my mind for this one!


#8

That’s a good suggestion. You can even create simulated presence sensors. I have several simulated switches that I use in testing and they are very helpful.


#9

I think I figured it out! After reading it again, slowly I realized that no matter what, the light will turn on @ 20% when they arrive home. They walk in and see the light on and we believe it went on when they left, but that’s not the case. The logic should read to turn the light to 20% if after sunset and they arrive.

I also confirmed this with debugging messages stating which rule triggered (leaving after sunset or coming home). Restructuring the logic and I will report back!


#10

Here is the updated logic, which should now work as intended:


#11

I like your use of the “debugging” statements. :slight_smile:

You can also use “Log to console” to do something similar even when logging level is set to None.


#12

Hahaha, yeah I had to make sure I am actually TOLD what’s going on when it happens otherwise I wouldn’t know what times to look for it! It’s a ST setup I did for a friend of mine after he saw my setup. Him and his wife are not very technical at all and we all know life happens…so I gave them a gentle reminder to fill me in on the status of the lights! :smiley: