Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95459

How to work out the position in the day relative to a time

$
0
0

@klogg wrote:

I hope I got someone’s attention because I really didn’t know how to describe my question in one line.

So, My lights go off every night at a ‘normal off time’ (say 23:00) but I need to account for other things like motion starting and stopping, and coming home after the normal off time.

The problem I’m having is knowing if the time now is after the normal off time.

I store the normal off time (not date) in an input_datetime so in a situation for example where motion occurs, how do I know if it is before or after 23:00 given that 23:30 and 01:30 are clearly both after 23:00 but mathematically 01:30 is not.

I currently have a VERY kludgy method that I have been using for over a year which uses all sorts of (what I thought when I first started out with HA were clever) tricks involving Boolean flags etc. but the time has come to rationalise my old code.

The only way I can think of is to store the time and date in the normal off time and have an automation that runs at midnight to add 24 hours to it. But that still feels a bit kludgy to me and liable to timing issues if things happen, like motion, at 00:00.

Posts: 14

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 95459

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>