Skip to content

Commit

Permalink
Version 0.1.2. First release
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythm authored May 14, 2024
1 parent 7de89e7 commit 3061532
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 82 deletions.
134 changes: 98 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# ad-Electrical Management

> [!NOTE]
> This README is currently under construction. Some configurations have changed or will change to make them more understandable during this process. Documentation on changes will only be given after the first release. Stay tuned!

The purpose of this app is to help reduce your electricity bill by:
- Automating charging times for electric vehicles (EVs), so they charge during off-peak hours when electricity rates are lower.
- Turning up/down heating sources and on/off hot water boilers based on electricity prices.
Expand Down Expand Up @@ -141,37 +137,61 @@ If you have not configured any namespace in your 'appdaemon.yaml' file, you can
> The app is designed to control electricity usage at your primary residence and will only adjust charging amps on chargers/cars that are within your home location. If you want to manage electricity consumption in other locations, I recommend setting up a separate Home Assistant and AppDaemon instance for each location.


### Charging
The app calculates the time required to charge electric vehicles based on State of Charge (SOC), battery sizes, and charger data. It also takes outside temperature into account to better estimate the time needed for charging if the maximum usage limit is expected to be below the necessary kW to maintain full charge speed.
## Charging
The app calculates electric vehicle (EV) charging time based on the State of Charge (SOC), battery size, and outside temperature provided using the `battery_size` configuration. If an SOC sensor or battery size isn't provided, it will be based on the maximum charged during one session on the charger.

> [!NOTE]
> If you have other high electricity consumption in combination with a low limit, it will reduce charging but not lower than 6 Ampere. This may result in unfinished charging if the limit is too low or consumption is too high during calculated charge time.
> If you have other high electricity consumption in combination with a low limit, it may reduce charging but not lower than 6 Amperes. This could result in unfinished charging if the limit is too low or consumption is too high during the calculated charge time.

The app supports controlling Tesla vehicles directly and Easee wall chargers. Documentation on how to implement other vehicles and chargers will be published upon request/donations.

For each vehicle, provide sensors to calculate the amount of kWh needed for charging, such as a charge limit and an SOC battery sensor. For each charger, include sensors to know if a car is connected and charging speed, etc. You can combine a Tesla vehicle with an Easee charger or use the Tesla vehicle to control charging even when connected to a charger without connectivity.


Currently supports controlling Tesla vehicles and Easee wall chargers. Charging Tesla by controlling an Easee charger is implemented but not yet tested. Documentation to request other cars or wall chargers will be published later.
### Configuration for all chargers

### Configuration for all vehicles and wall chargers
#### Priority settings for charger
Multiple cars with priority 1-5 are supported. The app queues the next car by priority when there is enough power available. If multiple chargers are in queue, charging vehicles will have to charge at full capacity before the next charger checks if it has 1.6kW of free capacity to start.
Multiple cars with priority levels 1-5 are supported by the app. The app queues the next car based on priority when there's enough power available. If multiple vehicles are in the queue, charging vehicles must reach full capacity before the next charger checks if it has 1.6 kW of free capacity to start.

- Priority 1-2: These cars will start at the calculated time even if starting will result in heaters turning down/off to stay below the consumption limit. They will also charge until complete even when exceeding the time before a price increase, due to turning down the speed based on the consumption limit.
Priority settings for cars include:

- Priority 3-5: These cars will wait to start charging until it is 1.6kW free capacity. They will also stop charging at the price increase after the calculated charge time ends.
- Priority 1-2: These cars will begin charging at the calculated time, even if it means reducing heating to stay below the consumption limit. They will continue charging until complete, regardless of any price increases due to adjusting the speed based on the consumption limit.

- Priority 3-5: These cars will wait to start charging until there is 1.6 kW of free capacity available. They will stop charging at the price increase that occurs after the calculated charge time ends.

#### Home Assistant helpers
Create helpers in Home Assistant to manage charging.
Create Home Assistant helpers to manage charging:

1. **Default Finish Time**: Charging is completed by default at 7:00 AM. To set a different hour for the charging to be finished, use an `input_number` sensor configured with `finishByHour`.
2. **Charge Now**: To bypass smart charging and charge immediately, configure `charge_now` as an `input_boolean`. The sensor will be automatically set to false after charging is completed or when the charger is disconnected.
3. **Charging on Solar Power**: If you generate electricity, you can choose to charge only during surplus production. Define another `input_boolean` and configure it with the `charge_on_solar` option.
4. **Guest Function**: There is a `guest` function defined with an `input_boolean` on chargers. This allows bypassing smart charging and avoids registering the maximum charged during one session and maximum amperage the car can charge.


Charging is by default finished by 7:00. To set a different hour the charging should be finished use an `input_number` sensor configured with `finishByHour`.
### Easee Charger
The Easee integration automatically detects wall charger information if its sensor names are in English; simply provide the name of your Easee using the `charger` option. If your sensors have names in another language, manually input the correct sensor names in the configuration. Check logs for any errors and provide missing sensors.

To bypass smart charging and charge now, you can configure `charge_now` with an `input_boolean` and set it to true. The sensor will be set to false after charging is finished or the charger is disconnected.
```yaml
easee:
- charger: nameOfCharger
charger_status: sensor.nameOfCharger_status
reason_for_no_current: sensor.nameOfCharger_arsak_til_at_det_ikke_lades
current: sensor.nameOfCharger_strom
charger_power: sensor.nameOfCharger_effekt
voltage: sensor.nameOfCharger_spenning
max_charger_limit: sensor.nameOfCharger_maks_grense_for_lader
online_sensor: binary_sensor.nameOfCharger_online
session_energy: sensor.nameOfCharger_energi_ladesesjon
```

If you are generating electricity, you can choose to charge only during surplus production. Define another `input_boolean` and configure it with the `charge_on_solar` option.
In addition to priority and the Home Assistant helpers described above, you can provide vehicle information. This can be either a Tesla or individual sensors. Please refer to the documentation on [configuring Easee & Tesla](#configuring-easee--tesla) or consult the section on [Vehicle Sensors](#vehicle-sensors).

### Tesla
### Configuring Tesla

> :warning: **WARNING**
> It is necessary to restart probably both Home Assistant and Appdaemon, and in some cases, reboot the vehicle to re-establish communications with the Tesla API after any service visits and also changes/reconfiguration of the integration in Home Assistant, such as if you need to update the API key.

Input the name of your Tesla with `charger`. Check logs for any errors.
Input the name of your Tesla using the `charger` option. Check logs for any errors and provide missing sensors.

```yaml
tesla:
Expand All @@ -180,25 +200,71 @@ Input the name of your Tesla with `charger`. Check logs for any errors.
battery_size: 100
```

### Easee
The Easee integration automatically detects the wall charger's information if its sensor names are in English; simply provide the name of your Easee with the `charger` option. However, if your sensors have names in another language, you must manually input the correct sensor names in the configuration.
### Configuring Easee & Tesla

This configuration sets up a Tesla charging on an Easee charger. Provide the name of your Easee charger using the charger option and the name of your Tesla vehicle using the carName option. A typical configuration should look something like this:

```yaml
easee:
- charger: nameOfCharger
charger_status: sensor.nameOfCharger_status
reason_for_no_current: sensor.nameOfCharger_arsak_til_at_det_ikke_lades
current: sensor.nameOfCharger_strom
charger_power: sensor.nameOfCharger_effekt
voltage: sensor.nameOfCharger_spenning
max_charger_limit: sensor.nameOfCharger_maks_grense_for_lader
online_sensor: binary_sensor.nameOfCharger_online
session_energy: sensor.nameOfCharger_energi_ladesesjon
easee_tesla:
- charger: leia
reason_for_no_current: sensor.leia_arsak_til_at_det_ikke_lades
current: sensor.leia_strom
charger_power: sensor.leia_effekt
voltage: sensor.leia_spenning
max_charger_limit: sensor.leia_maks_grense_for_lader
session_energy: sensor.leia_energi_ladesesjon
car: spacey
pref_charge_limit: 90
battery_size: 100
finishByHour: input_number.spaceyferdig
priority: 3
charge_now: input_boolean.spacey_ladna
```

The app stores the highest session energy in persistent storage, as this is the only indication of how much charge is needed to reach full capacity. It then calculates the time required for charging based on this information.
### Vehicle sensors

In addition to namespace and battery size you can provide the following vehicle sensors:

`carName`: Name of car.
`charger_sensor`: Charge cable Connected or Disconnected
`charge_limit`: SOC limit sensor in %
`battery_sensor`: SOC (State Of Charge) in %
`asleep_sensor`: If car is sleeping
`online_sensor`: If car is online
`location_tracker`: Location of car/charger.
`destination_location_tracker`: Destination of car
`arrival_time`: Sensor with Arrival time, estimated energy at arrival and destination.
`software_update`: If cars updates software it probably can`t change charge speed or stop charging
`force_data_update`: Button to Force Home Assistant to pull new data
`polling_switch`: Home Assistant input_boolean to disable pulling data from car
`data_last_update_time`: Last time Home Assistant pulled data
`battery_size`: Size of battery in kWh
`pref_charge_limit`: Preferred chargelimit


### Charger sensors

In addition to priority and HA sensors you can provide the following charger sensors:

`charger`: Name of your charger.
`charger_id`: Unique ID. Recommend using ID used to make API calls
`charger_sensor`: Charge cable Connected or Disconnected
`charger_switch`: Charging or not
`charging_amps`: Ampere charging
`charger_power`: Charger power in kWh
`session_energy`:: Charged this session in kWh
`volts`: Volt in charger. 230 or 400
`phases`: 1 or 3 phases


##### Just sensors for charging
You can try to define just sensors with defining a `charger` instead of Easee of Tesla if you have other brands. This has not been tested.
`charger_switch` must be a input boolean.
`charging_amps` must be a sensor with number.

If another vehicle is using the charger, you can disable logging of the highest session energy and maximum ampere that the guest vehicle can charge by using an Home Assistant input_boolean helper configured as `guest`. Enabling this sensor will initiate the charging session immediately.
> [!WARNING]
> The default location if no sensor for location is provided is 'home'. This will stop charging if you are controlling your car and not a wall charger if it is not chargetime. Please make sure your location sensor is functioning properly


## Climate
Expand Down Expand Up @@ -344,16 +410,12 @@ electricity:
finishByHour: input_number.finishChargingAt
priority: 3
charge_now: input_boolean.charge_Now
electric_consumption: sensor.tesla_electric_consumption_w
departure: input_datetime.departure # Not implemented yet
- charger: yourOtherTesla
pref_charge_limit: 70
battery_size: 80
finishByHour: input_number.yourOtherTesla_finishChargingAt
priority: 4
charge_now: input_boolean.yourOtherTesla_charge_Now
electric_consumption: sensor.tesla_electric_consumption_w
departure: input_datetime.departure_yourOtherTesla
easee:
- charger: nameOfCharger
Expand Down
10 changes: 8 additions & 2 deletions apps/ElectricalManagement/electricalManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

__version__ = "0.1.1"
__version__ = "0.1.2"

import appdaemon.plugins.hass.hassapi as hass
import datetime
Expand Down Expand Up @@ -731,6 +731,12 @@ def initialize(self):
# Setting up generic chargers
chargers = self.args.get('charger', [])
for t in chargers:
location_tracker = t.get('location_tracker',None)
if not location_tracker:
raise Exception (
"location_tracker sensor not provided in configuration for charger. Aborting Charger setup. "
"Please provide a location_tracker sensor to use this function"
)
namespace = t.get('namespace',None)
name = t.get('name',None)
charger_sensor = t.get('charger_sensor',None)
Expand All @@ -743,7 +749,7 @@ def initialize(self):
battery_sensor = t.get('battery_sensor',None),
asleep_sensor = t.get('asleep_sensor', None),
online_sensor = t.get('online_sensor',None),
location_tracker = t.get('location_tracker',None),
location_tracker = location_tracker,
destination_location_tracker = t.get('destination_location_tracker',None),
arrival_time = t.get('arrival_time',None),
software_update = t.get('software_update',None),
Expand Down
Loading

0 comments on commit 3061532

Please sign in to comment.