Dear HA-community,
I want to do the following thing and did not find an existing solution to adapt:
Charging our electric car during the best hours with dynamic electricity pricing.
I use these integrations:
GitHub - mampfes/ha_epex_spot: Adds EPEX Spot data to Home Assistant. (via HACS)
I did already manage to heat our water within the best 2 hours of the day with low prices.
But now I want to charge our ZOE within the best continuing hours (low prices).
I managed to find an algorithm to be able to calculate the hours, which I need to fully charge the car depending on battery charging level with the above integration of EPEX:
template:
- sensor:
# 100 - ZOE battery --> percentage that has to be charged --> divided by 100 --> multiplicated with 22 (capacity of the battery in kWh) --> divide this by 2.214 kWh (which can be charged within an hour) --> rounded down and plus 1 (to have enough time to finish charging, because after this time the shelly will shut down power for the car)
- name: ZOE-Aufladezeit
unique_id: "ZOELadezeitInStunden"
state_class: "measurement"
state: >-
{{ int((22 * ((100 - (float(states('sensor.batterie')))) / 100)) / 2.214) // 1 +1 }}
the code above I pasted in my /config/configuration.yaml
The testing routine was without failure and the algorithm gave me the right number.
The following routine should help me to identify the best time slot (with best pricing) to charge the car. I’d like to add that as “automation”:
# get the lowest price all day tomorrow:
service: epex_spot.get_lowest_price_interval
data:
earliest_start: "00:00:00"
latest_end: "07:00:00"
latest_end_post: 1
duration:
hours: XY
instead of “XY”, I’d like to insert the result of “{{ int((22 * ((100 - (float(states(‘sensor.batterie’)))) / 100)) / 2.214) // 1 +1 }}” as mentioned above.
But I did not find the right method to put it in instead of “XY”.
The following did not lead to suitable solution:
# get the lowest price all day tomorrow:
service: epex_spot.get_lowest_price_interval
data:
earliest_start: "00:00:00"
latest_end: "07:00:00"
latest_end_post: 1
duration:
hours: "states.sensor.zoe_aufladezeit"
The error message was:
“Fehler beim Aufrufen des Diensts epex_spot.get_lowest_price_interval. expected float for dictionary value @ data[‘duration’][‘hours’]. Got None”
What did I do wrong?
Thanks in advance.