How to subscribe to "Sunrise with negative offset" in an app?

Is there already something ready to use?
Or do I have to make the calculations myself and use runOnce (or similar)?

I know about subscribe location, 'sunrise', handler, but in my case when it's sunrise it's already to late...

There is an offset option in RM that can be negative as well.

1 Like

Thanx, but I'm not talking about RM,
I'm looking for in app solutions (coding question)...

I don’t recall seeing a way to subscribe to an offset, so I’m pretty sure it’s something you’d have to code for.

It’s not super straightforward, but ultimately the event you’re looking for is sunriseTime, like this:

subscribe(location, "sunriseTime", sunriseTimeHandler)

This will send an event with the time of the next sunrise. In your code, you take that time, calculate the offset, and set up a runOnce schedule for that time.

I highly recommend this page from the SmartThings API. I’ve always just stolen the code from this page, rather than trying to remember how to do it myself:

https://docs.smartthings.com/en/latest/smartapp-developers-guide/sunset-and-sunrise.html

2 Likes

Thanx a lot! :+1: :beers:

Why are such facts not in the official Hubitat Developer Documentation? :thinking:

  1. The HE team spends most of their time expanding the capabilities of the system.

  2. They basically copied a LOT of the functionality of SmartThings Classic. If they spent enough time (resources) to fully develop the documentation the platform would be lacking a lot of the functionality it has.

This is why those of us who do any coding use ST Classic documentation as a reference. It’s close enough.

:sunglasses:

I’m a bit embarrassed to admit it, but I didn’t even look at the Hubitat documentation before I answered your question. I started with SmartThings, so I usually go to their documentation out of habit. As @wayne.pirtle mentioned, the functionality is almost identical. I don’t think I’ve ever found anything in the SmartThings documentation that’s missing in Hubitat.

1 Like

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