Use input_number as storage for value solar_angle?

HI,

right now, I use this notification to tell me at what solar angle my light sensor is turning on the lights:

  - service: notify.notify
    data_template:
      message: >
        {{as_timestamp(now()) | timestamp_custom("%X") }}: Outdoors lights set and safely lit 
         while Solar angle is {{states('sensor.solar_angle')}}.

Could I use the input_number.set_value somehow to store that value? And restore state at reboot?

Im considering disabling the light sensor, (because only a few lights are connected) and have all my outside lights set through HA, using the solar_angle.

Please have a look for me ?

First create an input_number:

input_number:
  solar_angle:
    name: Solar Angle
    mode: box
    min: 0
    max: 90

Note: set min and max to whatever the min and max possible values the sun angle can output (I didn’t ckeck)

Then in whatever automation/script you have have it sending that notification, add another action:

      - service: input_number.set_value
        data_template:
          entity_id: input_number.solar_angle
          value: "{{states('sensor.solar_angle')}}"  
1 Like

I should add - I don’t really understand what your ultimate goal is… are you just trying to figure out what the solar angle is when your lights come on today, then you’re going to use that to, make an automation to just turn them on when the solar angle gets to that level?

Wouldn’t it be easier to just make an automation based on sunset with a time offset?

Edit: like so:

automation:
  trigger:
    platform: sun
    event: sunset
    offset: "-00:45:00"
action:
    service: homeassistant.turn_on
    entity_id: group.outside_lights

That would turn the lights on 45 min before sunset.

lol. no, right now my lights are powered when an external light sensor switches on power to the lights. This is a non-smart device, but it switches the lights on on a light level I like.
The only way for me to make this smart is check the sun angle when that happens. Ive been monitoring that now for some time, but would like to ‘save’ the angel in the input_number.

If I am satisfied the sun angle is round and about the same when the lights turn on, I can use that, in a new automation as a trigger and take out the external light sensor.

I don’t think the sunset offset is as constant as the sun angle for this purpose and, but I could of course also check that. Any idea how I could add the offset to my current notification?

—edit—

@tom_l suggests:

{{ (as_timestamp(states.sun.sun.attributes.next_setting) - as_timestamp(now())) | timestamp_custom('%H:%M:%S', 0) }}

up next to test, thanks all

getting back to this, I think this describes it quite nicely https://www.home-assistant.io/docs/automation/trigger/#sun-trigger

This is also useful when the “sunset” event is not dark enough outside and you would like the automation to run later at a precise solar angle instead of the time offset such as turning on exterior lighting.

with my current automations id like to capture the correct solar angle.

I can use that later on in the ‘new’ automation. Not sure if I need elevation and a minus setting, or azimuth? Both are solar angle?

this is what I use for solar_angle:

  solar_angle:
    friendly_name: 'Sun Angle'
    unit_of_measurement: '°'
    value_template: >
      {{ '%+.1f'|format(state_attr('sun.sun','elevation')) }}

and from what I noticed up to now, lights go on at about -4 indeed, as the example shows…

for an update. Im ‘recording’ the solar angle with:

# Update Solar angle outside light variable
  - alias: 'Update Solar angle outside'
    id: 'Update Solar angle outside'
    initial_state: 'on'
    trigger:
      platform: state
      entity_id:
        - binary_sensor.outside_daylight_sensor
#      to: 'off'
    action:
      service: variable.set_variable
      data:
        variable: solar_angle_outside_light
        attributes_template: >
          {
                "history_1": "{{ variable.state }}",
                "history_2": "{{ variable.attributes.history_1 }}",
                "history_3": "{{ variable.attributes.history_2 }}",
                "history_4": "{{ variable.attributes.history_3 }}",
                "history_5": "{{ variable.attributes.history_4 }}"
          }
      data_template:
        value: >
          {{states('sensor.solar_angle')}}

##########################################################################################
# Variable
##########################################################################################

variable:
  solar_angle_outside_light:
    value: 'Not yet set'
    restore: true
    attributes:
      icon: mdi:format-rotate-90
      name: 'Solar angle outside light' 

will see what that brings

Wait. Hang on a minute…

Firstly, won’t your light sensor be affected by other factors than just the sun elevation angle e.g. the amount of cloud cover?

And secondly, variable:?!?!?!?

What is this? (unless it is the custom component that I am aware of but the name of which I can’t recall, and you are just teasing us by not mentioning it in your post?)

well, now that you mention that, I have never given that any thought, but have never had any reason too. It has been working for the last 20 years without a hiccup… So I gather it’s reliable enough to test for solar_angle.

Yes the CC. I disable it most of the time, since HA dev’s warn us not to use CC when issues arise, but have it ready for these kind of needs.

It works without any issue and there hasn’t been any error whatsoever, so rather happy to use its fine properties HA lacks out of the box.
this is it: https://github.com/rogro82/hass-variables

I hit Trigger few times, and now wait for the binary_sensor to do the triggering next:
17