From 3d882784c9a62603dd6dd57387dfc410b29657ce Mon Sep 17 00:00:00 2001 From: Skeletitor Date: Sun, 14 Apr 2024 21:51:04 +0200 Subject: [PATCH] - added value template for grid mode. Grid mode is human readable now. --- fenecon2mqtt/CHANGELOG.md | 7 ++++ fenecon2mqtt/config.yaml | 2 +- .../fenecon2mqtt/publish_hassio_discovery.py | 39 ++++++++++++------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/fenecon2mqtt/CHANGELOG.md b/fenecon2mqtt/CHANGELOG.md index 8e3f311..d3cb017 100644 --- a/fenecon2mqtt/CHANGELOG.md +++ b/fenecon2mqtt/CHANGELOG.md @@ -1,5 +1,12 @@ +## 0.2.16 + +- !!!**update manually or reinstall the addon**!!! added new default entities/channels to be requested in FEMS see -> [hassio forum](https://community.home-assistant.io/t/add-on-fenecon2mqtt-connect-fenecon-home-openems-energy-storage-systems-to-homeassistant/561823). +- added value template for state values of inverter and charger0 an charger1. States are human readable now. **Thx BenniJu** +- added value template for grid mode. Grid mode is human readable now. +- cleaned up docker image files + ## 0.2.15 - !!!**update manually or reinstall the addon**!!! added new default entities/channels to be requested in FEMS see -> [hassio forum](https://community.home-assistant.io/t/add-on-fenecon2mqtt-connect-fenecon-home-openems-energy-storage-systems-to-homeassistant/561823). diff --git a/fenecon2mqtt/config.yaml b/fenecon2mqtt/config.yaml index 410eff7..00342c0 100644 --- a/fenecon2mqtt/config.yaml +++ b/fenecon2mqtt/config.yaml @@ -1,6 +1,6 @@ # https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config name: Fenecon2Mqtt -version: "0.2.15" +version: "0.2.16" slug: fenecon2mqtt description: Provides data from Fenecon Home Websocket as a Homeassistant device and HA entities. Fenecons channels are configurable. url: "https://github.com/Skeletitor/ha_addon_fenecon2mqtt" diff --git a/fenecon2mqtt/rootfs/usr/bin/fenecon2mqtt/publish_hassio_discovery.py b/fenecon2mqtt/rootfs/usr/bin/fenecon2mqtt/publish_hassio_discovery.py index 0d2dedf..0c74ee4 100644 --- a/fenecon2mqtt/rootfs/usr/bin/fenecon2mqtt/publish_hassio_discovery.py +++ b/fenecon2mqtt/rootfs/usr/bin/fenecon2mqtt/publish_hassio_discovery.py @@ -36,6 +36,21 @@ } } +val_tmpl_state = '''{% set mapper = { + "0": "Ok", + "1": "Info", + "2": "Warning", + "3": "Fault"} %} +{% set state = value | string %} +{{ mapper[state] if state in mapper else state }}''' + +val_tmpl_gridmode = '''{% set mapper = { + "-1": "Undefined", + "1": "On-Grid", + "2": "Off-Grid"} %} +{% set gridmode = value | string %} +{{ mapper[gridmode] if gridmode in mapper else gridmode }}''' + def get_entity_device_class(unit): logger = logging.getLogger(__name__) def_cla = None @@ -78,9 +93,16 @@ def get_entity_unit_of_measurement(unit, name, type): # Correct Fenecons new Sum Unit. Return None if no unit is given return None if unit == "" else unit.replace('_Σ','') -def get_entity_value_template(value_template): +def get_entity_value_template(c): logger = logging.getLogger(__name__) - return value_template + + ret_val = "{{value}}" + if c in ["charger0/State", "charger1/State"]: + ret_val = val_tmpl_state + elif c == "_sum/GridMode": + ret_val = val_tmpl_gridmode + + return ret_val def get_hassio_overwrite(channel, config): logger = logging.getLogger(__name__) @@ -105,13 +127,6 @@ def get_hassio_overwrite(channel, config): def publish_hassio_discovery(mqtt, fenecon_config, version): logger = logging.getLogger(__name__) logger.info('Start publish hassio dicovery') - state_mapper = '''{% set mapper = { - "0": "Ok", - "1": "Info", - "2": "Warning", - "3": "Fault"} %} -{% set state = value | string %} -{{ mapper[state] if state in mapper else state }}''' for c in config.fenecon['fems_request_channels']: #if c == '_meta/Version': @@ -142,7 +157,7 @@ def publish_hassio_discovery(mqtt, fenecon_config, version): fems_unit, fems_type = get_fems_values(fenecon_config, component, channel) # json_template_entity['unit_of_meas'] = ow_device_unit or get_entity_device_unit(fenecon_config['result']['payload']['result']['components'][component]['channels'][channel]['unit']) json_template_entity['unit_of_meas'] = ow_device_unit or get_entity_unit_of_measurement(fems_unit , json_template_entity['name'], fems_type) - json_template_entity['val_tpl'] = ow_value_template or get_entity_value_template("{{value}}") + json_template_entity['val_tpl'] = ow_value_template or get_entity_value_template(c) json_template_entity['dev_cla'] = ow_device_class or get_entity_device_class(json_template_entity['unit_of_meas']) json_template_entity['stat_cla'] = ow_state_class or get_entity_state_class(json_template_entity['dev_cla']) json_template_entity['stat_t'] = config.hassio['mqtt_broker_hassio_queue'] + "/" + hassio_uid @@ -152,11 +167,9 @@ def publish_hassio_discovery(mqtt, fenecon_config, version): json_template_device['ops'] = fenecon_config['result']['payload']['result']['components'][component]['channels'][channel]['text'] json_template_device['stat_t'] = config.hassio['mqtt_broker_hassio_queue'] + "/" + hassio_uid #json_template_device['val_tpl'] = "{{value}}" - json_template_device['val_tpl'] = state_mapper + json_template_device['val_tpl'] = val_tmpl_state mqtt.publish(config.hassio['mqtt_broker_hassio_discovery_queue'] + "/config", json.dumps(json_template_device), 0, True) else: - if c in ["charger0/State", "charger1/State"]: - json_template_entity['val_tpl'] = state_mapper mqtt.publish(config.hassio['mqtt_broker_hassio_discovery_queue'] +"/" + hassio_uid + "/config", json.dumps(json_template_entity), 0, True) logger.info('End publish hassio dicovery')