Getting data from home assistant

Hi there. I want to learn to make PCBs and therefore I realised a closet light which is controlled by a esp.

Is it possible for esphome to read values from an home assistant instance? I want to put the esp into deep sleep on day and turn it on when the sun sets. This data I could provide from home assistant.

You cannot wake from deep sleep from anything external, because the esp is asleep.

You might be able to get the esp to get the time that it should wake from homeassistant, then set deep sleep until that time.

Let me clarify: I want to use the sun rise and set data to put the esp into deep sleep. Sun rise will determine when and sun set for how long. According to the documentation there is sleep_duration.

My problem is that I don’t understand how to the esp could read the data from home assistant.

Is ESP wired to HA?
You may try to give a pulse to ESP to wake up. Perhaps the simplest wiring to try to sense a serial input. Any character is starting with a start bit, which i normally from high to low transition.

1 Like

Can you better explain what the device will
Do?

It is a little circuit that controls a mosfet based on a distance sensor: if the door is open light will turn on and if the closet door is closed it will turn off. In addition to that I would like to put the esp into deep sleep when there is daylight. I could go for static times but then you have different lighting conditions in winter and summer. I thought that I might use the sun data from home assistant but I’m missing how I can utilize it on the esp.

There’s an ESPhome component that does exactly this: https://www.esphome.io/components/sun.html

You can use triggers from this component to enter/prevent deep sleep as you see fit: https://www.esphome.io/components/deep_sleep.html#deep-sleep-enter-action

1 Like

I would use this you only need the time from another source, like home assistant, but that is super easy.
I’ll use the on_sunrise event to go to sleep, then you’ll have to write a lambda to convert the value returned by next sun set into time and feed that to the deep sleep.

Is your esp battery powered? Is the light battery powered?

1 Like

@bachya & @glmnet I’m blind. Thanks for the hint

1 Like

You may get a NTP server time, too, whether your ESP is connected to a router and then to internet. Otherwise there might be a NTP server on the HA system.

I have the PCB now and I am stuck at converting the strftime back into a numerical value. Do you have any hints on how to achieve that?