Rule Conditional

Is there a way to compare either the current time or sunset to be less than a specific time?

I want a rule to turn a light on at either a set time or an offset from sunset but only of the sunset offset is less than a specific time.

Ex: Turn light on at 4:30 PM or SS-30 but only if SS < 8:00 PM.

There are likely multiple ways to do this. What I would do is:

2 Likes

Do you want it to turn on at the earlier or the later time?

This is what I finally generated. The 'CurrentTime' is a HUB variable. When I look at the local variable, ReqTime, it's value has not changed since I created it. I could probable make CurrentTime local and set it the way I set CurrentTime. There is really no reason to have the 'CurrentTime' a global variable. It would be nice if the system had a global variable that always returned the local current time.

Will this work?

Thanks,

Milt

It looks like it should work. Let us know if something seems off after it ran or should have. Turning on debugging can help pinpoint issues as needed.

You might want to see this post if you only want it to run once per day. As it is set up right now, it looks like it will run twice per day except when Sunset - 30 minutes happens to be at 4:30 also.

I did realize that the code might run twice, although I hoped the system would run only since the light would already be on when the second trigger time occurred. On the other hand since the switch is a dimmer it might be a,poor, attempt to change the level at the second time. That would be absurd since the two time will reverse as sunset changes.

I am working two other solutions, one recently suggested, that I will post later, after I clear the snow, for comments.

I would like to point to a suggestion that would be immensely useful. The system, according to documentation, generates both sunset and sunrise at 12:01 AM. When this is done there should be global variables created for both times that are accessible but invariant to user code. Since Hubitat is largely, but not entirely, driven by time events, offsets from both sunrise and sunset should be directly accessible from Rules. For me anyway this would be a huge advantage.

Regards,

Milt

Initially set a trigger; in my case it is for one or more times. I
don't think this is particularly relevant.

Go to Create Actions and create a Conditional action. The choice is
"IF Expression THEN". I then select "->New Condition". The dropdown
shows a number of choices, on of which is "Time of Day". If I select
that option then I can choose "Sunset" the code does NOT provide an
ability for selecting a relatio nal operator, only an offset. The
condigiont then resolves to: "If (Time is Sunset(4:48 PM)(F)[FALSE]
THEN)".

The have the ability to make a relational test between Sunset and
another time, I have to create a local variable "SunsetTime" and
assign it to "sunset". When I then have the dropdown from
"->Condition" I can choose "Varaible". This allows me to compare the
"SunsetTime" variable to another time, in my case another local
variable with a specific time.

This is the reason I believe the system should generate global(HUB)
variables when the sunset and sunrise times are calculated, 12:01 AM,
that are accessible to the user by invariant to change.

The two choices I currently have are shown below. One is from a
suggestion that uses a boolean to track the state and the other is one
that specifically tests the state of the light of interest.

This is how I handle those situations:

Thanks,

Thanks.
I have created two HUB varriables, LocalSunset and LocalSunrise. I have a Rule that triggers at 8:00 AM every day to set the two variables. I created the rule since I don't know whether a HUB variable associated with DateTime will be automatically updated. I suppose I should try it myself to see.

Milt

You may want to add a trigger for if the hub reboots also. (Capability: Location Event, Sub menu SystemStart)

I did add the suggested trigger. I wondered what might happen after a power failure. This is the answer. Thank you.

I have not seen that part of the forest before. All of the sunrise and sunset data is in that table. Why are the values for sunrise and sunset not exposed for use as variables in Rules?

On reboot, it rechecks sunrise and sunset. There is probably little to no chance that it would have changed from what you have stored in your variables from 8 AM unless the reboot happens at exactly the right time to mess you up. Not having a rule to update would guarantee that would happen LOL

Technically, they are available as "specific times." However, if you want to do comparisons that involve offsets, then you need to put them into variables yourself.

Based on the suggestion for using the Location Event I added a "Location Event: systemStart" rule that will turn off all lights between 11:00 PM and 8:00 AM after a system start. I added this because I don't know whether the system puts lights back to the state that existed at a power failure when the system recovers.
If lights are on at 9:00 PM and we get a power failure that is corrected at 2:00 AM I don't want lights coming back on.

Actually I will probably test this - easy to turn a light on and power cycle the hub.

Hopefully you meant reboot (From the settings page) instead of power cycle. But, on the off chance that you did not, please use the software methods for shutting down and/or rebooting. It is much safer for your database.

Thank you, but yes, I have dealt with fixing pcs for a number of years after power failures when I did not have UPS protection.

BTW - Is there any way to connect a hub to a UPS and get a shutdown signal from the UPS?

Don't think the hub can sense the UPS unless it has some sort of network integration. Then you would have to come up with a driver.

I use the Ring Range Extenders to sense when the power is down and then issue a command to shut down the hub if it does not come on within an hour (Rule Machine can handle this)

Seems to require the ring base station

Amazon'sChoicefor [ring range extender]

$24.99

[FREE Returns ]

  • Expand the reach of your Ring Alarm Base Station to your Ring Alarm components
  • Easy installation with no tools required
  • Plugs into standard wall outlets
  • Requires the Ring Alarm Base Station and only boosts the Ring Alarm system network

Nope, I have it directly connected to the hub.

2 Likes