I want an input boolean to be true if sun is below horizon with an offset AND time is between 22:00 and 05:00. If one of these conditions is not true the boolean must be false.
I would like to only use one automation for this. Is this possible and if yes how?
Does this need to be an input boolean⌠i.e. do you need to maintain the ability to manually turn it on and off? If not, then you can do it with 0 automations by creating a Template binary sensor.
Is your offset time-based or solar elevation-based?
Errors often are self-explanatory, so it would be better when you post the error here.
It looks like you are still working in the legacy sensor format, and the code from Didgeridrew is in the modern format.
In your case it probably should be something like:
That helped, no error anymore
However it seems to be ON right now which shouldn´t be the case.
Only if sun is below -5.5 and time is between 22:00 and 05:00
Shouldn´t it be < -5.5 and 22 <= now().hour < 5 }}" ?
Great!
Yes, with the current template the sensor is ON (or true) when the sun elevation is above -5.5 deg and the time is between 05:00 and 22:00, so in any other case it is OFF.
You could argue âwhatâs in a nameâ, and can easily use this for any further usage by selecting OFF instead of ON, but indeed your proposal inverts the template behavior.
For a Sun Trigger, the word offset refers to time. Thatâs why I assumed you were referring to time when you said âsun is below horizon with an offsetâ.
In contrast, when discussing the sunâs elevation, as when used with a Sun Elevation Trigger, thereâs no reference to âoffsetâ. The sunâs elevation is merely a positive (above horizon) or negative (below horizon) value.
Thatâs why both Didgeridrew and I asked for clarification about your use of the word âoffsetâ. In a template, itâs easier to use the sunâs elevation than performing time arithmetic with sunset or sunrise. Had âoffsetâ been time, the template would have been a bit longer.
Okay I will try that.
Actually I just noticed this in the logs ( it does not return an error on the frontend though)
2023-08-09 15:08:42 WARNING (MainThread) [homeassistant.components.template] Template binary sensor âsun_and_timeâ has no entity ids configured to track nor were we able to extract the entities to track from the availability template(s). This entity will only be able to be updated manually.
2023-08-09 15:08:54 ERROR (MainThread) [homeassistant.components.template.binary_sensor] Could not render available template sun_and_time: UndefinedError: âhas_valueâ is undefined
Actually I am still on version 0.103.6 so maybe that is why.
Template editor shows âError rendering template: UndefinedError: âhas_valueâ is undefinedâ
Ok⌠for future reference, you should start with that information. Youâre more than 3 years behind the current version and there have been significant changes to templates (as well as nearly every other integration) since then.
availability_template: "{{ states('sun.sun') not in ['unavailable', 'unknown'] }}"
Yes I forgot to mention at start⌠sorry
Using availability_template: "{{ states('sun.sun') not in ['unavailable', 'unknown'] }} returns an error however.
2023-08-09 17:24:36 ERROR (MainThread) [homeassistant.components.homeassistant] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while scanning a quoted scalar
in â/home/homeassistant/.homeassistant/binary_sensors.yamlâ, line 424, column 32
found unexpected end of stream
in â/home/homeassistant/.homeassistant/binary_sensors.yamlâ, line 424, column 90
I really want to update as soon as I get some more spare time. Some integrations does not work anymore, some new stuff can´t be integrated and so on, but I think most of my existing yaml programming won´t work anymore and needs to be redone afterwards.
But updating is definitely on my todo list.