Skip to content

Commit

Permalink
Merge pull request #108 from canton7/unique_id
Browse files Browse the repository at this point in the history
Add unique_ids to configuration.yaml, modbusLAN.yaml, modbusUSB.yaml
  • Loading branch information
williamjeccles authored Mar 12, 2023
2 parents 804d1f5 + d049f39 commit 09936e7
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 85 deletions.
198 changes: 113 additions & 85 deletions custom_components/HA-FoxESS-Modbus/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,63 @@ modbus: !include custom_components/HA-FoxESS-Modbus/modbusLAN.yaml
sensor:
- method: left
name: pv1_sum
unique_id: foxess_inv1_pv1_sum
platform: integration
round: 2
source: sensor.pv1_power
unit_time: h
- method: left
name: pv2_sum
unique_id: foxess_inv1_pv2_sum
platform: integration
round: 2
source: sensor.pv2_power
unit_time: h
- method: left
name: pv_total_sum
unique_id: foxess_inv1_pv_total_sum
platform: integration
round: 2
source: sensor.pv_power_now
unit_time: h
- method: left
name: load_sum
unique_id: foxess_inv1_load_sum
platform: integration
round: 2
source: sensor.load_power
unit_time: h
- method: left
name: bat_charge_sum
unique_id: foxess_inv1_bat_charge_sum
platform: integration
round: 2
source: sensor.battery_charge
unit_time: h
- method: left
name: bat_discharge_sum
unique_id: foxess_inv1_bat_discharge_sum
platform: integration
round: 2
source: sensor.battery_discharge
unit_time: h
- method: left
name: feedin_sum
unique_id: foxess_inv1_feedin_sum
platform: integration
round: 2
source: sensor.feed_in_power
unit_time: h
- method: left
name: grid_consumption_sum
unique_id: foxess_inv1_grid_consumption_sum
platform: integration
round: 2
source: sensor.grid_consumption
unit_time: h
- platform: integration
name: losses_sum
unique_id: foxess_inv1_losses_sum
source: sensor.system_losses
unit_time: h
method: left
Expand All @@ -75,115 +84,134 @@ sensor:
#Templates enable math operations against states/values to give us better data
template:
- sensor:
- name: "Battery Discharge"
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.battery_discharge_power') | float(default=0) ) > 0 %}
{{ states('sensor.battery_discharge_power') | float(default=0) * 1 }}
{% else %}
0
{% endif %}
- name: "Battery Charge"
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.battery_discharge_power') | float(default=0) ) < 0 %}
{{ states('sensor.battery_discharge_power') | float(default=0) * -1 }}
{% else %}
0
{% endif %}
- name: "Feed In Power"
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.grid_ct') | float(default=0) ) > 0 %}
{{ states('sensor.grid_ct') | float(default=0) * 1 }}
{% else %}
0
{% endif %}
- name: "Grid Consumption"
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.grid_ct') | float(default=0) ) < 0 %}
{{ states('sensor.grid_ct') | float(default=0) * -1 }}
{% else %}
0
{% endif %}
- name: "PV Power Now"
device_class: "power"
unit_of_measurement: "kW"
state: >
{{ (states('sensor.pv1_power') | float(default=0) + states('sensor.pv2_power') | float(default=0) ) * 1 }}
- name: "PV Energy Daily"
device_class: "energy"
unit_of_measurement: "kWh"
state: >
{{ ((states('sensor.pv1_daily') | float(default=0) + states('sensor.pv2_daily') | float(default=0) ) * 1 ) | round(2) }}
- name: "System Losses"
device_class: "power"
unit_of_measurement: "kW"
state: >
{{ ((states('sensor.pv1_power') | float(default=0)
+ states('sensor.pv2_power') | float(default=0)
+ states('sensor.grid_consumption') | float(default=0)
+ states('sensor.battery_discharge') | float(default=0)
- states('sensor.battery_charge') | float(default=0)
- states('sensor.feed_in_power') | float(default=0)
- states('sensor.load_power') | float(default=0) )) | round(2) }}
- name: "Time Period 1 - Start Time"
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_1_start') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Time Period 1 - End Time"
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_1_end') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Time Period 2 - Start Time"
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_2_start') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Time Period 2 - End Time"
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_2_end') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Battery Discharge"
unique_id: foxess_inv1_battery_discharge
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.battery_discharge_power') | float(default=0) ) > 0 %}
{{ states('sensor.battery_discharge_power') | float(default=0) * 1 }}
{% else %}
0
{% endif %}
- name: "Battery Charge"
unique_id: foxess_inv1_battery_charge
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.battery_discharge_power') | float(default=0) ) < 0 %}
{{ states('sensor.battery_discharge_power') | float(default=0) * -1 }}
{% else %}
0
{% endif %}
- name: "Feed In Power"
unique_id: foxess_inv1_feed_in_power
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.grid_ct') | float(default=0) ) > 0 %}
{{ states('sensor.grid_ct') | float(default=0) * 1 }}
{% else %}
0
{% endif %}
- name: "Grid Consumption"
unique_id: foxess_inv1_grid_consumption
device_class: "power"
unit_of_measurement: "kW"
state: >
{% if (states('sensor.grid_ct') | float(default=0) ) < 0 %}
{{ states('sensor.grid_ct') | float(default=0) * -1 }}
{% else %}
0
{% endif %}
- name: "PV Power Now"
unique_id: foxess_inv1_pv_power_now
device_class: "power"
unit_of_measurement: "kW"
state: >
{{ (states('sensor.pv1_power') | float(default=0) + states('sensor.pv2_power') | float(default=0) ) * 1 }}
- name: "PV Energy Daily"
unique_id: foxess_inv1_pv_energy_daily
device_class: "energy"
unit_of_measurement: "kWh"
state: >
{{ ((states('sensor.pv1_daily') | float(default=0) + states('sensor.pv2_daily') | float(default=0) ) * 1 ) | round(2) }}
- name: "System Losses"
unique_id: foxess_inv1_system_losses
device_class: "power"
unit_of_measurement: "kW"
state: >
{{ ((states('sensor.pv1_power') | float(default=0)
+ states('sensor.pv2_power') | float(default=0)
+ states('sensor.grid_consumption') | float(default=0)
+ states('sensor.battery_discharge') | float(default=0)
- states('sensor.battery_charge') | float(default=0)
- states('sensor.feed_in_power') | float(default=0)
- states('sensor.load_power') | float(default=0) )) | round(2) }}
- name: "Time Period 1 - Start Time"
unique_id: foxess_inv1_time_period_1_start_time
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_1_start') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Time Period 1 - End Time"
unique_id: foxess_inv1_time_period_1_end_time
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_1_end') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Time Period 2 - Start Time"
unique_id: foxess_inv1_time_period_2_start_time
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_2_start') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
- name: "Time Period 2 - End Time"
unique_id: foxess_inv1_time_period_2_end_time
icon: "mdi:calendar-clock"
state: >
{% set raw_time = states('sensor.time_period_2_end') | int %}
{% set hours = raw_time // 256 %}
{% set minutes = raw_time - (hours * 256) %}
{{ strptime(hours | string + ":" + minutes | string, '%H:%M').time() }}
# Utility Meters - Provides meters to be used with the energy dashboard and reset daily
utility_meter:
load_daily:
unique_id: foxess_inv1_load_daily
source: sensor.load_sum
cycle: daily
pv1_daily:
unique_id: foxess_inv1_pv1_daily
source: sensor.pv1_sum
cycle: daily
pv2_daily:
unique_id: foxess_inv1_pv2_daily
source: sensor.pv2_sum
cycle: daily
bat_charge_daily:
unique_id: foxess_inv1_bat_charge_daily
source: sensor.bat_charge_sum
cycle: daily
bat_discharge_daily:
unique_id: foxess_inv1_bat_discharge_daily
source: sensor.bat_discharge_sum
cycle: daily
feedin_daily:
unique_id: foxess_inv1_feedin_daily
source: sensor.feedin_sum
cycle: daily
grid_daily:
unique_id: foxess_inv1_grid_daily
source: sensor.grid_consumption_sum
cycle: daily
losses_daily:
unique_id: foxess_inv1_losses_daily
source: sensor.losses_sum
cycle: daily
Loading

0 comments on commit 09936e7

Please sign in to comment.