twhittock / eo_mini

EO Mini integration for Home Assistant
MIT License
12 stars 6 forks source link

Time Entities for charge schedule #5

Open badguy99 opened 1 year ago

badguy99 commented 1 year ago

I mentioned this before, and just wanted to note it here, as I'm going to be away for a while, so not likely to get to this soon, in case it helps anyone else looking at it.

Time entities are in the new 2023.6 release - https://www.home-assistant.io/blog/2023/06/07/release-20236/#new-entities-date-time-datetime - hopefully they will be able to set some sort of step so minutes can change only to 00 or 30, but I haven't looked.

As I see things there are probably 8 entities to add -

I had some thoughts / random notes on how the schedule could be handled (feel free to ignore all of this, I just wanted to note it somewhere in case it helps)

from datetime import time

st = time(11, 0)
et = time(16, 30)

sidx = int(st.hour * 2 + st.minute / 30)
eidx = int(et.hour * 2 + et.minute / 30)

sched = 'PPP0000000000000000000SSSSSSSSSS00000000000PPPPP00'

# Adding new schedule when start time < end time
If the string is loaded to a list it can be indexed and may be easier for manipulation

sched_list = list(sched)
sched_list.pop()  # 2 times to remove last two 0 as they aren't used
sched_list[sidx:eidx]= "S" * (eidx - sidx)
sched = "".join(sched_list)
sched = sched + "00" # need to add the 00s back on

sched
'PPP0000000000000000000SSSSSSSSSSSS000000000PPPPP00'

if sidx > eidx:  # The time period loops past midnight
sched_list[0:eidx-1] = "T" * (eidx-1)
sched_list[sidx:len(sched_list)] = "T" * (len(sched_list) - sidx)

start time from string to time object -
>>> time(sched.index("S") // 2, (sched.index("S") % 2) * 30)
datetime.time(11, 0)

end time from string to time object -
>>> time(sched.rindex("S") // 2, (sched.rindex("S") % 2) * 30)
datetime.time(15, 30)

Checking current time schedule...
sched_list[0] == sched_list[-1] # indicates the schedule loops past midnight

Still need something to read start / end time when it loops around midnight

Off peak - "P"
Scheduled Time - "T"
Solar - "S"

Things that might need to be taken in to account:

Should also add itertools.cycle might help with the rotating past midnight issue, and might simplify some things.

Rubenconzels commented 1 year ago

This would be really handy as EO cloud service is unreliable. Unfortunately I lack the skillset to help