Hi!
I’m looking for a way to create a kind of sensor calculating the average time of the day an event happened in my house for the last x days.
Background:
I built “in bed” sensors, which turn on night-mode (very dim lights). With a newborn in house, it would be very handy to turn on this night mode about 30 minutes before we usually go to bed to not wake her up if she’s sleeping already. I could look into the last days and make the time fixed, but:
- times differ between weekdays and weekend
- times shift during the year
What I need
- sensors spitting me out the average time binary_sensor.night_mode switched to on for the last 10 weekdays / 5 weekend days / 5 mondays…
What I tried to do (did not work)
- use statistics sensor (does not take input_datetime)
- use filter sensor (does not take input_datetime)
What I think could be working (but seems very cumbersome to do)
- convert input_datetime to a sensor with decimal numbers (20:30 would be 20,5), apply filter sensor with moving average and convert it back to a time
- create an array of input_datetime sensors (weekday_time_1, weekday_time_n, […] weekday_time_10), write the first time-change to 1, on every time-change move existing value to n+1 and the new value to 1, then calculate average of sensor_n=1 to sensor_n=10 using templating (somehow); Do the same for weekends
What I need you for:
- There must be an easier way of achieving this. I just can’t believe I’ m the only person feeling the need of using past data / your usual routines to automate things in the house.
So, any ideas?