Doh! I’ll get this if it kills me lol!!
OK All working now except the graph.
gr2:
name: Daylight Hours
entities:
- sensor.daylighttoday
hours_to_show: 168
refresh: 1800
Is producing Unknown… (At the right… everything else is from before I changed to seconds) Maybe I should try the sun.sun…
You have to add unit_of_measurement to your sensor (e.g. unit_of_measurement: sec
.)
in the history graph?
In the sensor config.
trying that in sensor config… didn’t like it in history graph…
Edit: I think it’s going to want sec in quotes…
Quotes are not necessary.
(Still unknown)
You’ll see the real values after a bit. Be patient.
hahaha!!.
I might need to make another dummy sensor…
So I’ve abandoned this because it is plotting the hours only… Made a new sensor as per:
daylengthchange:
friendly_name: 'Change in Day Length'
unit_of_measurement: sec
value_template: >
{{ (states.sun.sun.attributes.daylight) - (states.sun.sun.attributes.prev_daylight) }}
icon_template: mdi:weather-sunny
If I put the value template in the dev template tool I get 88.0 which is correct.
I also created a history graph:
gr2:
name: Day Length Change
entities:
- sensor.daylengthchange
hours_to_show: 168
refresh: 1800
and also a history-graph in lovelace:
- type: history-graph
title: Day Length Change
hours_to_show: 168
refresh_interval: 1800
entities:
- sensor.daylengthchange
But in lovelace and normal states it shows no history available… If I go to the states and find sensor.daylengthchange and click on it I get the right values and a state of 88.0
Why aren’t I seeing a graph? Must be missing something simple…
Is this just for “coolness” or do you have an endgoal in mind with this information?
Coolness I suppose… does it matter? Just a visual way to see the days getting longer or shorter…
I was just curious! This whole thread has been an interesting read.
EDIT: I kinda want to implement it, but I don’t know what to use it for… LOL.
FWIW, I’ve been involved in multiple discussions about using sunrise and sunset in templates, and how it’s a real pain because the standard sun component only provides next_sunrise and next_sunset, which makes many templates pert near impossible to implement easily. And the sun-based trigger and condition code use the same sunrise and sunset values - they’re just not exposed as attributes in the sun component. IMHO, they should be added as standard attributes in the standard component. Now, if I was setup to make pull requests…
I think it’s possible to just edit the component on github and submit it as a pull request?
I still can’t get the history graph to work. I know I’m just missing something fundamental here…
show me the code and i’ll make the change. I’ve gone through the process before, it’s not too bad. I don’t have an environment set up… I just use the web ui and notepad++. It’s just more time consuming.
If it were that easy…
If you’re interested in the “cost of entry”, start reading here.
Can you describe what you’re getting or not getting? If you have an entity with a unit_of_measurement, and add it to a history graph, it should “just work.”
My understanding was that you have to install all the test tools, run tests, etc. on the changes before submitting a PR. If you’re up to it…
https://github.com/pnbruckner/homeassistant-config/blob/master/custom_components/sun.py