Does Ha have a built in day/night cycle?

Does HA have a sleep mode\night mode function built in?

I’d like to have a number of automations that perform slightly different actions depending on whether it’s “Night” or “day”.

For example, “night” begins at 23:00 and ends at 05:00, and “day” is will be the opposite. During “night” the light switches will turn the lights on at a low value on a single press, and will require a double press to go to full brightness, and during “Day” they will simply toggle on\off at full brightness with no double press action. While the motion sensors on the lights will do nothing during the day and will switch the corresponding lights on during the night, and do nothing during the day.

I’d like to use the sleep\night mode times for multiple things and have it set centrally rather than coding it in individually into each automation.

Would I be better off simply coding helpers and checking to see if the value is between them in each automation, or is there a globally implemented system to handle this already?

I’m going to need to do this based on fixed values, rather than based on actual lux levels or local sunrise\sun set times, as this is an arbitrary designation rather than being related to actual day\night.

As a global project, Home Assistant respects each user’s right to define day and night for themselves, based on whatever personal, cultural, geographical, political, temporal, and/or astronomical criteria they wish to use. :grin:

There are variety of methods discussed in the following thread:

1 Like

You can use above or below horizon in the sun integration

Or if that does not suit you could create your own time span using times of day.

Based on your use case, do you really want “day/night”, or maybe it would be better to check if it was “dark/light” outside? So your lights would turn on to 80% if it was very cloudy even in the middle of the day. So, since everyone’s approach to this is slightly different, it’s a feature, not a limitation, of HA that you need to make your own - so you can do it exactly the way that works best for you.

I’m afraid that my needs are literal and arbitrary. I need to set a period during which all lights will default to a dimmer setting regardless of actual light levels.

Then you will have to define an arbitrary and literal custom trigger for your case :slight_smile:

1 Like

Or you can look at installing adaptive lighting to help with this.

All of this complexity, and I just need it to something different between two times.

When it comes to this platform, if you ask a vague or general question it is very likely you will receive responses with a variety of general methods that may accomplish what you have described. We don’t know anything about the structure, constraints, options, or needs of your automation or devices unless you share it…

Community Guide: Asking a Good Question

1 Like

We don’t know anything about the structure, constraints, options, or needs of your automation or devices unless you share it…

I was referring to HA having a half a dozen different ways to determine what is constituted as day\night, but not the obvious one of having a field that you fill in to tell it directly.

The problem that I’ve found with HA is that it’s exceedingly good at letting you create bespoke solutions that are tailored to your exact needs, but rather poor when it comes to simply giving you a button to press to do something.

Personally, I’d consider asking if something had a built in day\night cycle to be a pretty direct question that doesn’t have much nuance. The system might be simple or complex, it just needs to be a built in system that will return “Day” based on a series of variables, or “Night” based on another series of variable. What the variables are could be a follow up question.

Community Guide: Asking a Good Question

Ironically, I asked one of the big AI chat bots this, and it wrote me a template that returned day\night based on the time helper.

The bot gave me the best answer.

I have a feeling that AI capable of writing simple code may be a game changer for people like me who just want simple solutions to clearly defined problems.

Glad it worked. Don’t lean too hard on them, they have proven inaccurate with HA quite a few times already. Personally I would rather learn the system myself because then when I want to do something the AI can’t handle I know how - but to each their own and no judgement.

This is actually a very accurate and fair assessment of HA.

Though whether this is a good thing or a problem entirely depends on your individual situation and expectations.

I was more suggesting that the bots were better at answering my questions than the community, because the bots didn’t over complicate things.

For example, in this instance the bot gave me some code that had two outputs, day and night. Because my question had binary choice in it.]

it didn’t talk about variable light levels, or suggest that I might want to use light sensors. It just gave code that split the day into two sections.

I’m curious, what was the answer of AI?

I would create a boolean (on-off) and create a automation around that.
If time is 22:00 then turn boolean off, if time is 06:00 then turn boolean on.
Off = Night
On = Day

There is no need for all that.

You’ve already been given this very simple solution:

It can be set up via the UI, no need for YAML.

  • Give it a name.
  • Give it an on time.
  • Give it an off time.
  • Done.

You can then use the state of this binary sensor wherever you want, including in conditions.

4 Likes

A couple of observations, now that the original question has been answered several different ways.

First, I’m surprised AI gave the right answer here. I’d be curious to see it. For me, so far, AI has always confidently given a very simple and straightforward answer which looked ideal. But each time it was totally incorrect and unworkable. In AI terms, a pure hallucination.

Second, I’m impressed by the depth of the answers in this thread. In some other environments the OP would have gotten the direct and technically correct answer to the specific question: No. HA doesn’t have that exact option built in.

Instead, even without knowing the specific use case, a number of workable solutions were offered. HA is very flexible and you can make things as simple or as complex as you’d like. Most of us think of that as a benefit. But if all you want is a simple “set it and forget it” appliance which requires no tinkering, then there are better options for you.

In hindsight, the obvious answer

Create a time helper to store an AM and a PM time, create a temple that returns a pre defined text value based on whether or not you’re currently between the two times.

Then simply read it from the automation using conditions.

The bit that I appreciate the most is that rather than just suggesting what to do it actually generated the code for me. So that I could copy and paste it right in. It was fully commented, too.

I’d like it if more people would simply post code to this forum. I’ve had trouble before with armchair experts telling me to “read the manual” and making out that I was simply making a mistake somewhere in the code when something didn’t function as expected, and when I asked them if they could replicate the solution on their own systems they just linked to the manual again. Eventually it turned out that I was going going down the wrong path, and that the armchair experts hasn’t understood the error message any more than I had, and were leading me down the wrong path because they hadn’t even tried to replicate the problem on a system that they knew was properly set up.

Eventually someone came along who understood what the error was, and it took about 10 seconds to fix everything.

1 Like

I’ve been on the HA forums almost daily for over 7 years now and I will say that in my experience that is very far from true. I would bet money that if you look in almost every thread someone will have posted some code (of course if that is the appropriate to the topic).

But (caveat) that might also depend on the way the question is being posed.

If you post the use case you are trying to achieve with the code that you tried that is giving the error and along with the error message if there is one the vast majority of the time you will get a great response and with corrected code.

If you post an error without any code you will most likely get a response of “post the code you tried that isn’t working and what do you expect it to do”.

If you post a general question on “how do I…” and no other context you are more likely to get a link to the documentation. This is not a Nabu Casa help desk (or an AI bot) that will do all of the work for you. we generally expect you to at least put in the initial work to try to figure it out on your own first. Then if it still doesn’t work and you post what you tried then most of the time you will get more specific help.

Remember, all of the help you get here is unpaid. So in effect we are all “armchair experts”. Tho some are more “experts” than others. An in fact it is exceedingly rare for any true “experts” to be on this forum ever at all since most Nabu Casa employees never come on here to provide any help at all.

4 Likes