Turn off the light an hour after sunrise

You can probably use the text sensor and automation as I said above in ESPHOME to do the trigger.
I don’t think it will work if your time source is not available, ie HA or SNTP, as the sunset sensor in ESPHOME needs to get its time from somewhere to know when Sunset and Sunrise is.

I think the gps time sensor would work without a network. But not cheap to add a gps to every esp.

Another option for use without network would be RTC module, in china these modules are very cheap. But, then again… why would a person want to build a standalone automation with ESPHome system and then not connect it to HA? I bet there are easier options to do it in this case (Arduino, for a start…).
My decision to make a standalone automation is that i’d like to have ligths lit in my front door even if by any chance HA is not running, or when i’m “working” on it and restart every few minutes…etc… system must work flawlessly. Ok, i could decide to use LDR resistor and measure light, but … i found sun dependancy more “fancy” :blush:

If its only for when HA is not running, ie if you still have internet connectivity, could you use SNTP instead of HA time source ?

Also, no idea how often esphome checks HA for time. If it checks regularly but keeps the sunset/sunrise times, it may still work if HA is down for a short period of time.
Could you setup the sun sensor and see if the sunrise/sunset times remain in the esphome webserver when HA is down ?

Old topic, but thought I would share the way I did this. Granted, this entire setup is on my gate which has a battery installed, with an esp01 for the gate button, gate button LED, binary sensor for open/closed etc, so this may be a bit of a challenge using it directly on mains as I don’t have any statements including if’s & or’s etc for when power might be off at the time of automation running.

Anyway, the only way I managed to get the offset of the button backlight to come on “Roughly” one hour before sunrise was a -5 degree offset.


sun:
  latitude: !secret latitude
  longitude: !secret longitude
  on_sunset:
    - then:
        - light.turn_on:
            id: ${id_led}
            transition_length: 20s
            brightness: 80%
        - delay: 1h
        - light.turn_on:
            id: ${id_led}
            brightness: 100%
            effect: pulse
  on_sunrise:
    - elevation: -5°
      then:
        - light.turn_on:
            id: ${id_led}
#            transition_length: 20s
            brightness: 80%
            effect: none
        - delay: 1h
        - light.turn_off:
            id: ${id_led}
            transition_length: 20s

Maybe this can steer someone in the correct direction and then post it here and I could steal that code for my own nefarious projects lol :rofl:

Great, thanks. However lately i use scheduler card for many things. It’s very customizable and friendly…

scheduler card?

Is this an addon for dashboards in the frontend, like Mushroom cards?

Sorry for the maybe stupid question, but I’m still very new to HA.

Yep, look in HACS store. Great and very usefull integration.

This becomes very noticeable as you get to higher latitudes - I’m at 60N the sun barely dips below the horizon in the summer and sets really early in the winter. What I need is to know when the sun is a number of degrees below the horizon - this should give similar light level levels winter or summer, but the time after sunset will be quite different.

Try these template sensors.

  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: "degrees"
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"        

sunAngle

1 Like

You do realize this is an esphome forum right? When people ask in a specific forum like this one is, HA template sensors don’t work in esphome. Do people in the HA channel want my esphome template sensors for their automations? No, they are useless for them.

did you try the esphome documentation? Seems like a crazy idea but if you type, “sun” into the search box in the website, that’s how you find out how to use the position of the sun in an automation.

Would a delay of 23 hours to the sunrise not be almost equivalent to triggering an hour in advance of sunrise?

Exceptions:

  • daily: this is not exactly 1 hour before sunrise, as it is bases on the dwy before
  • twice a year: daylight saving changes will cause an issue