A card that tells me when I should start various appliances, but only when there actually is some data. #111
AkshayRao27
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Credit & Disclaimer
I generated most of this code using ChatGPT 4, as well as with the Home Assistant Assistant GPT. I'm not a programmer by any stretch of the imagination, and this post is a mix of documentation & instruction, so that when I inevitablity forget how any of this works about 2½ weeks from now, future me has something to fall back on. If you need any kind of technical help with any of the stuff below, I don't know how much I will be able to contribute ¯\_(ツ)_/¯
What this card does
x
hours" timer).x
hours" timer).The Card
All Schedules:
Only some schedules:
Prerequisites
1. Install the necessary integrations
This card requires the EPEX Spot Sensor integration to create the entities that will feed it data, as well as Card Tools & Secondary Info entity Row for actually creating the card. All of these can be installed via HACS.
2. Create EPEX Spot Sensors
You need one EPEX Spot Sensor that determines the cheapest time-window for each cycle of each appliance. In my case, that meant three sensors.
After installing the integration, create a "helper" by going to Settings → Devices & Services → Helpers → Create Helper → EPEX Spot Sensor.
My dishwasher cycle takes 3 hours & 15 minutes to run, and I don't care when the dishwasher comes on, so this is how I configured that sensor:
For the washing machine however, I don't want to have a batch end after 11 pm or before 5:30 am. That way I can take care of putting the laundry on the drying rack before going to bed / heading to work instead of leaving it in the washing machine to ferment like a nice Sourdough loaf. So this is how I configured the 30° / 60° Batch Sensors (with slightly different values of course):
These are the three sensors that we will be extracting data from
3. Create Template Sensors for extracting the correct time
Once all of the EPEX Spot Sensors are set up, we need to extract either the start or the end time depending on the appliance.
Since I can only tell my dishwasher when to start, I need to know what time I should start it at.
Create a Template Sensor by going to Settings → Devices & Services → Helpers → Create Helper → Template → Template a sensor. Under "State Template", enter
WAT
Here's what's happening:
future_windows
wherestate_attr('binary_sensor.dishwasher_cheapest_window', 'data')
retrieves the data attribute frombinary_sensor.dishwasher_cheapest_window
.This data is a list of up to two entries for
start_time
(I am using smartENERGY.at which gives me data for the present day and the next day).
selectattr('start_time', 'gt', now().timestamp() | timestamp_local | list %)
filters thestart_time
list and selects entries wherestart_time
is greater than (gt
) the current timestamp (now().timestamp()
), converted to the local timezone (| timestamp_local
). This ensures only future windows are considered. Then,| list %
converts the filtered result back into a list (since the filtering process apparently does not return a list).if future_windows
is NOT empty (%
), thenstrptime
(future_windows[0]['start_time'], '%Y-%m-%dT%H:%M:%S%z')
parses thestart_time
of the first ([0]
) future window from a string, into a datetime object (%Y-%m-%dT%H:%M:%S%z
), allowing us to then usestrftime
('%H:%M on %d/%m/%y')
** to format the datetime object as we want.else: Waiting for new data
: In casefuture_windows
is indeed empty, that means that all of the possiblestart_times
are in the past, and we need to wait for new data from the provider.Now for the two washing machine sensors. Here, we need the
end_time
and not thestart_time
. The rest of the code is essentially the same. Here's the 30° Batch Sensor:For the 60° Batch Sensor, simply replace
binary_sensor.30deg_batch_cheapest_window
withbinary_sensor.60deg_batch_cheapest_window
4. Create Template Sensors for calculating the duration
Knowing what time to start the dishwasher is one thing, but when I actually schedule it in the appliance, I need to tell it how many hours from now it should start the cycle. To calculate this, we can create another Template Sensor with this code:
The first few lines are essentially the same. Here's what's happening with the additional bits:
start_time
just like before usingstrptime
but then also calculate the difference between thestart_time
and the current time (now()
) in seconds, and save it in a new variable this time (time_till_start
){:02}
).time_till_start
by 3600 to get the number of hours and displays the result as an integer (| int
).%
) by 60 to get the minutes and displays the result as an integer.Again, we do the same thing for the two washing machine sensors, but use
end_time
. Here's what the 30° Batch Sensor looks like:These are the six sensors that we will use for building our card
Card Code
In your dashboard, add a "Vertical Stack", select "Show Code Editor" and paste in:
Beta Was this translation helpful? Give feedback.
All reactions