Skip to content

Commit

Permalink
Send null values instead of -1 values (#65)
Browse files Browse the repository at this point in the history
Send null values instead of -1 values, which avoids recording -1 values in FlexMeasures, while still correctly spacing the data sent.

This is possible since FlexMeasures/flexmeasures#549.


* Send null values instead of -1, which avoids recording -1 values in FlexMeasures while still correctly spacing the data sent

* Fix comparison of None with int (minimum SoC)

* Compare to min SoC setting instead of hardcoded value

* Add car_min_soc_in_percent in set_fm_data config settings
  • Loading branch information
Flix6x committed Dec 30, 2022
1 parent e680d1e commit 948e9ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -436,11 +436,11 @@ set_fm_data:
fm_soc_entity_address: !secret fm_soc_entity_address

fm_chargepower_resolution_in_minutes: !secret fm_quasar_event_resolution_in_minutes
car_min_soc_in_percent: !secret car_min_soc_in_percent

wallbox_host: !secret wallbox_host
wallbox_port: !secret wallbox_port
wallbox_modbus_registers: !include /config/appdaemon/apps/v2g-liberty/app_config/wallbox_modbus_registers.yaml

```

## Configure HA to use v2g-liberty
Expand Down
27 changes: 15 additions & 12 deletions set_fm_data.py
Expand Up @@ -2,7 +2,7 @@
import json
import math
import requests
from typing import List
from typing import List, Union
import appdaemon.plugins.hass.hassapi as hass
from wallbox_client import WallboxModbusMixin
from util_functions import time_round, time_ceil
Expand Down Expand Up @@ -69,9 +69,9 @@ class SetFMdata(hass.Hass, WallboxModbusMixin):
current_availability_since: datetime
availability_readings: List[float]

# State of Charge (SoC) of connected car battery. If not connected set to -1.
soc_readings: List[int]
connected_car_soc: int
# State of Charge (SoC) of connected car battery. If not connected set to None.
soc_readings: List[Union[int, None]]
connected_car_soc: Union[int, None]


def initialize(self):
Expand All @@ -89,7 +89,7 @@ def initialize(self):
self.listen_state(self.handle_charge_power_change, "sensor.charger_real_charging_power", attribute="all")

# SoC related
self.connected_car_soc = -1
self.connected_car_soc = None
self.soc_readings = []

# Availability related
Expand Down Expand Up @@ -127,12 +127,12 @@ def handle_soc_change(self, entity, attribute, old, new, kwargs):
if isinstance(reported_soc, str):
if not reported_soc.isnumeric():
# Sometimes the charger returns "Unknown" or "Undefined" or "Unavailable"
self.connected_car_soc = -1
self.connected_car_soc = None
return
reported_soc = int(round(float(reported_soc), 0))

if reported_soc == 0:
self.connected_car_soc = -1
self.connected_car_soc = None
return

self.log(f"Processed reported SoC, self.connected_car_soc is now set to: {reported_soc}%.")
Expand Down Expand Up @@ -397,11 +397,14 @@ def is_available(self):
# How to take an upcoming calendar item in to account?

charge_mode = self.get_state("input_select.charge_mode")
# Forced charging in progress if SoC is below 20%
if self.is_car_connected() and charge_mode == "Automatic" and self.connected_car_soc >= 20:
return True
else:
return False
# Forced charging in progress if SoC is below the minimum SoC setting
if self.is_car_connected() and charge_mode == "Automatic":
if self.connected_car_soc is None:
# SoC is unknown, assume availability
return True
else:
return self.connected_car_soc >= self.CAR_MIN_SOC_IN_PERCENT
return False



Expand Down

0 comments on commit 948e9ab

Please sign in to comment.