Hi All,
Just having a little difficulty understanding the different Template Syntax that appears in various examples.
The Difference between using,
value_template:
"{{ ( states('sensor.sdm220m_3_import_active_energy') | float | round(1)) -
( states('sensor.sdm220m_2_import_active_energy') | float | round(1))}}"
#As Opposed to:-
state: >
{{ states ('sensor.sdm220m_3_import_active_energy') | float(2) | round(2)
- states ('sensor.sdm220m_2_import_active_energy') | float(2) | round(2)}}
I have got one of the templates I want working,
# Calculate Inverter Production - Alternate Code
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 }}
This one doesn’t; errors at Classes etc when I check before reboot.
# Calculate Inverter Production
- platform: template
sensors:
net_production:
value_template:
"{{ ( states('sensor.sdm220m_3_import_active_energy') | float | round(1)) -
( states('sensor.sdm220m_2_import_active_energy') | float | round(1))}}"
unit_of_measurement: "kWh"
device_class: energy
#state_class: total_increasing #Causes Error
#state_class: measurement #Causes Error
#attributes:
# last_reset: "1970-01-01T00:00:00+00:00"
friendly_name: Inverter Net Production
Other one I have an issue with is this, which I think needs State.class: measurement to allow me to do a Max/Min statictic Graph.
# Calculate Inverter Power
sensor:
- platform: template
sensors:
net_power:
value_template:
"{{ ( states('sensor.sdm220m_3_power') | float | round(1)) -
( states('sensor.sdm220m_2_power') | float | round(1))}}"
unit_of_measurement: "W"
device_class: power
#state_class: measurement #Causes Error
friendly_name: Inverter Net Power
The above does return the Net Power value, which I can Graph Like this, just as I do with my Main Eastron Meter…
But I can’t do the statistical Chart that I can do off the Eastron’s power reading.
I believe that may be due to the missing Measurement state.class.
Can’t anyone steer me in the right direction to get my head around this.
Thanks.