pnbruckner / ha-sun2

Home Assistant Sun2 Sensor
The Unlicense
236 stars 22 forks source link

[Sensors] Add Delta Sensors for daylight, night, etc #106

Closed baylanger closed 6 months ago

baylanger commented 11 months ago

Hello.

Would it be possible to add delta sensors for daylight, night, and perhaps others? The delta for each would be the difference between the previous and current day. During winter time, once solstice is behind us, it can bring some "joy" to visualize the increased in daylight. Those deltas should probably be in seconds.

Perhaps this can be done using template but before trying to go this long way, I wanted your opinion on this.

I've done a bit of Python in the past but not at the level of the code used in this integration, so the reason to raise this issue. If I know how to do one, I could probably figure out how to do them all ;)

Thanx for this integration, very useful.

pnbruckner commented 11 months ago

Interesting idea. Yes, this would be easy to add, but there is already a LOT of entities created by this integration, and I'm not sure how many people would use these sensors. For now, how about a template sensor based on something like this:

{{ ((state_attr('sensor.home_sun_daylight', 'today')
   - state_attr('sensor.home_sun_daylight', 'yesterday')) * 3600)|round }}
baylanger commented 11 months ago

I agree, there's already a lot of sensors here :)

I didn't know it was possible to specify "yesterday", that makes life easy. I'll use that. Thanx for providing that example.

As an example, I wonder if adding this example in the README would make sense for others that could be looking to do something similar with any sensors.

pnbruckner commented 6 months ago

That's kind of Templating 101. Not sure it makes sense to add to this integration's doc page.