I’m trying to use the sun elevation as a condition for a sensor.
The sensor switches on but not at the right moments.
The goal is to switch on at about 4° and off around -5°.
I have played with the upper/lower limits and hysteresis but I cannot get it right.
Is it because of that negative value?
Could be value… or the time of day or your trigger…maybe post it so people can have a look?
Also…recently I got pointed to the Sun2 custom solution…also very nice creating various sensors (instead of using the attribs)
So I have a sensor (sensor.sun_elevation) that stores the sun’s elevation angle.
I would like to use that value with the threshold integration to create a sensor that switches on & off at 4° and -5° respectively.
Tried with different limits/hysteresis values, using only lower or upper, …
Thanks for that hint on the sun2 sensor but I don’t see how this can help.
@nickrout: I know that the condition on itself doesn’t do anything but if the sensor is not working as expected, the result of the automation will also not be what I wanted so I’m trying to get this right at first.
Is what I like to achieve not possible with a threshold sensor?
I’m not saying you are wrong. I am just trying to help out the OP with his templates, which he says are not rendering properly. (Mind you, he hasn’t showed us them yet!)
Guys, thanks for the tip on the sun2 sensor.
It’s in my nature, and seems more logic to me, to try to work with standard tools (dunno how to explain it in a better way) so I was under the impression that I don’t need any additional things then ‘standard HA’ to get this working.
I mean, I try to avoid adding/installing extra stuff if it’s not needed.
Thank you for your persistence to help me, really appreciate it!
I have posted the code in my reply to nickrout (have you not seen it?): there is nothing more yet because I wanted to get the condition/sensor right first hence the ‘testsun’ name.
Nickrout’s reply is exactly what I needed; it gives me what I need to use as a condition in my automations.
I’d like to share what I have on this subject. This also includes dusk and dawn, so not binary sensor any more. Obviously you can play with the thresholds to get a better fit to where you are.
template:
- sensor:
# dawn-day-dusk-night
- name: "Period of the day"
unique_id: period_of_the_day
state: >
{% set elevation = state_attr('sun.sun', 'elevation') %}
{% set rising = state_attr('sun.sun', 'rising') %}
{%- if elevation <= -4.4 -%}
night
{%- elif -4.4 < elevation <= +3 -%}
{{ 'dawn' if rising else 'dusk' }}
{%- else -%}
day
{%- endif -%}light
icon: >-
{% set elevation = state_attr('sun.sun', 'elevation') %}
{% set rising = state_attr('sun.sun', 'rising') %}
{%- if elevation <= -4.4 -%}
mdi:weather-night
{%- elif -4.4 < elevation <= +3 -%}
mdi:weather-sunset-{{ 'up' if rising else 'down' }}
{% else %}
mdi:weather-sunny
{% endif %}
The idea and codes are not mine, but here and there from the community (couldn’t recall where now). Just figured it is a good opportunity to share.