I have the following Template Sensor to calculate my Inverter Production.
template:
- sensor:
- name: "Inverter_Production"
unique_id: "inverter_net_prod_test"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: >
{{ states ('sensor.sdm220m_3_import_active_energy') | float(2) | round(2)
- states ('sensor.sdm220m_2_import_active_energy') | float(2) | round(2)}}
availability: >
{{ states ('sensor.sdm220m_3_import_active_energy') | float(none) != none and
states ('sensor.sdm220m_2_import_active_energy') | float(none) != none }}
It is no longer working as it now returns a negative value as smd220_3 has rolled over at 100,000
Result
template:
- sensor:
- name: "Inverter_Production"
unique_id: "inverter_net_prod_test"
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: >
-68165.73999999999
availability: >
True
I have added 100,000 to the value in the Template Editor Which has it returning the correct value, but this will become invalid when the other meter rolls over.
state: >
{{ states ('sensor.sdm220m_3_import_active_energy') | float(2) | round(2)
- states ('sensor.sdm220m_2_import_active_energy' ) | float(2) | round(2) + 100000}}
Can anyone suggest a better approach for this method, given that both meter s will eventually roll over each time they hit 100,000.
Thanks.