Skip to content

Commit

Permalink
control of charge using pvpc available
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain1971 committed Apr 22, 2023
1 parent acb0b9e commit 20af11d
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 17 deletions.
104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,107 @@ cards:
name: Ajusta ICarga
icon: mdi:current-ac
```

OR USING pvpc control ( you need to configure pvpc on the integration config ):
```
type: vertical-stack
cards:
- type: markdown
content: <CENTER><H1>CARGADOR COCHE</H1></CENTER>
- type: horizontal-stack
cards:
- type: gauge
entity: sensor.v2c_trydan_sensor_fvpower
severity:
green: 0
yellow: 8000
red: 9500
needle: true
min: 0
max: 10000
name: Producción FV
- type: gauge
entity: sensor.v2c_trydan_sensor_housepower
name: Consumo hogar
severity:
green: -10000
yellow: 0
red: 0
needle: true
min: -10000
max: 10000
- type: gauge
entity: sensor.v2c_trydan_sensor_chargepower
name: Cargando en el coche
needle: true
min: 0
max: 8000
severity:
green: 0
yellow: 7200
red: 7700
- type: entities
entities:
- entity: sensor.v2c_trydan_sensor_chargestate
name: Estado
secondary_info: none
- entity: switch.v2c_trydan_switch_dynamic
name: Control dinámico
secondary_info: last-changed
- entity: switch.v2c_trydan_switch_paused
name: En pausa
icon: mdi:play
secondary_info: last-changed
- entity: switch.v2c_trydan_switch_locked
name: Bloquedado
icon: mdi:play
secondary_info: last-changed
- entity: sensor.v2c_trydan_sensor_intensity
name: Intensidad de carga
secondary_info: last-changed
- entity: sensor.v2c_trydan_sensor_minintensity
name: Mínimo dinámica
secondary_info: last-changed
- entity: sensor.v2c_trydan_sensor_maxintensity
name: Máximo dinámica
secondary_info: last-changed
- entity: sensor.v2c_trydan_sensor_chargeenergy
name: Energía cargada
secondary_info: none
- entity: sensor.v2c_trydan_sensor_chargekm
name: Km Cargados
secondary_info: none
- entity: sensor.v2c_trydan_sensor_chargetime
name: Tiempo de carga
- entity: number.v2c_km_to_charge
name: Km a Cargar
secondary_info: last-changed
icon: mdi:car-arrow-right
- entity: sensor.v2c_precio_luz
- entity: switch.v2c_trydan_switch_v2c_carga_pvpc
name: Carga por Precio
- entity: number.v2c_maxprice
- type: conditional
conditions:
- entity: switch.v2c_trydan_switch_dynamic
state: 'on'
card:
type: entities
entities:
- entity: number.v2c_min_intensity
name: Ajusta Imin dinámica
icon: mdi:current-ac
- entity: number.v2c_max_intensity
name: Ajusta Imax dinámica
icon: mdi:current-ac
- type: conditional
conditions:
- entity: switch.v2c_trydan_switch_dynamic
state: 'off'
card:
type: entities
entities:
- entity: number.v2c_intensity
name: Ajusta ICarga
icon: mdi:current-ac
```
6 changes: 5 additions & 1 deletion custom_components/v2c_trydan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.const import CONF_IP_ADDRESS

from .const import DOMAIN, CONF_KWH_PER_100KM
from .const import DOMAIN, CONF_KWH_PER_100KM, CONF_PRECIO_LUZ

DATA_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -46,6 +46,7 @@ class V2CtrydanOptionsFlowHandler(config_entries.OptionsFlow):
def __init__(self, config_entry: config_entries.ConfigEntry):
self.config_entry = config_entry
self.current_kwh_per_100km = config_entry.options.get(CONF_KWH_PER_100KM, 20.8)
self.current_precio_luz = config_entry.options.get(CONF_PRECIO_LUZ, "sensor.precio_luz")

async def async_step_init(self, user_input=None):
if user_input is not None:
Expand All @@ -56,6 +57,9 @@ async def async_step_init(self, user_input=None):
vol.Required(
CONF_KWH_PER_100KM, description={"suggested_value": self.current_kwh_per_100km}
): vol.Coerce(float),
vol.Optional(
CONF_PRECIO_LUZ, description={"suggested_value": self.current_precio_luz}
): str,
}
)

Expand Down
3 changes: 2 additions & 1 deletion custom_components/v2c_trydan/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DOMAIN = "v2c_trydan"
CONF_IP_ADDRESS = "ip_address"
CONF_KWH_PER_100KM = "kwh_per_100km"
CONF_KM_TO_CHARGE = "km_to_charge"
CONF_KM_TO_CHARGE = "km_to_charge"
CONF_PRECIO_LUZ = "precio_luz"
2 changes: 1 addition & 1 deletion custom_components/v2c_trydan/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"quality_scale": "internal",
"requirements": ["aiohttp"],
"ssdp": [],
"version": "2.9.1",
"version": "2.9.2",
"zeroconf": []
}
43 changes: 42 additions & 1 deletion custom_components/v2c_trydan/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
_LOGGER = logging.getLogger(__name__)

async def async_setup_entry(hass, config_entry, async_add_entities):

async_add_entities([MaxIntensityNumber(hass)])
async_add_entities([MinIntensityNumber(hass)])
async_add_entities([KmToChargeNumber(hass)])
async_add_entities([IntensityNumber(hass)])
async_add_entities([IntensityNumber(hass)])
async_add_entities([MaxPrice(hass)])

class MaxIntensityNumber(NumberEntity):
def __init__(self, hass):
Expand Down Expand Up @@ -175,3 +177,42 @@ async def async_set_native_value(self, value):
else:
_LOGGER.error("v2c_intensity must be between {} and {}".format(self.native_min_value, self.native_max_value))

class MaxPrice(NumberEntity):
def __init__(self, hass):
self._hass = hass
self._state = 0

@property
def unique_id(self):
return "v2c_MaxPrice"

@property
def name(self):
return "v2c_MaxPrice"

@property
def icon(self):
return "mdi:currency-eur"

@property
def native_value(self):
return self._state

@property
def native_step(self) -> float | None:
return 0.001

@property
def native_max_value(self):
return 1.000

@property
def native_min_value(self):
return 0.000

async def async_set_native_value(self, value):
if 0 <= value <= 1.0:
self._state = value
self.async_write_ha_state()
else:
_LOGGER.error("v2c_MaxPrice must be between 0 and 1")
Loading

0 comments on commit 20af11d

Please sign in to comment.