TBH, I started to get fed up with the current state of the iotawatt integration, it doesn’t do what I want anymore (I don’t want energy values that reset daily), and I wanted to be able to customise how each sensor could be presented.
Dealing with a custom_integration is painful as it breaks too easily and I didn’t want to maintain yet again another piece of software.
So I went back to the good old days of defining sensors, using REST and templates. This gives me energy sensors that only get reset on January 1st of each year (like it used to).
As I have defined a REST sensor as such:
sensor:
- platform: rest
name: IoTaWatt (Select)
resource: http://192.168.10.3/query?select=[Export.wh,Import.wh,Total.wh,Total_Solar.wh]&begin=y&end=m&group=all&header=yes
json_attributes:
- labels
- data
value_template: "on"
and:
template:
sensor:
- name: iotawatt
unique_id: iotawatt
state: >
{
{%- for i in range(0, state_attr('sensor.iotawatt_select', 'labels')|length|default(0)) -%}
"{{ state_attr('sensor.iotawatt_select', 'labels')[i] }}": {{ state_attr('sensor.iotawatt_select', 'data')[0][i] }}{% if not loop.last %}, {% endif %}
{%- endfor -%}
}
- name: iotawatt_export_kwh
unique_id: iotawatt_export_kwh
device_class: energy
unit_of_measurement: kWh
state_class: total_increasing
state: >
{{ (states("sensor.iotawatt")|from_json).Export|float / 1000 }}
- name: iotawatt_import_kwh
unique_id: iotawatt_import_kwh
device_class: energy
unit_of_measurement: kWh
state_class: total_increasing
state: >
{{ (states("sensor.iotawatt")|from_json).Import|float / 1000 }}
- name: iotawatt_total_kwh
unique_id: iotawatt_total_kwh
device_class: energy
unit_of_measurement: kWh
state_class: total_increasing
state: >
{{ (states("sensor.iotawatt")|from_json).Total|float / 1000 }}
- name: iotawatt_solar_kwh
unique_id: iotawatt_solar_kwh
device_class: energy
unit_of_measurement: kWh
state_class: total_increasing
state: >
{{ (states("sensor.iotawatt")|from_json).Total_Solar|float / 1000 }}
the creates like sensor.iotawatt_import_kwh with all the attributes you need to be used in the energy screen, and I can display as a card all that I used so far.
they get refresh every 30s, but the REST sensor can let you change how often you are fetching. With the query above, there’s no point querying it more than every minute.
If you want from the last 2y of data, the query is something like:
http://192.168.10.3/query?select=[Export.wh,Import.wh,Total.wh,Total_Solar.wh]&begin=y-1y&end=m&group=all&header=yes
If you want from a particular date, constant
http://192.168.10.3/query?select=[Export.wh,Import.wh,Total.wh,Total_Solar.wh]&begin=2023-01-01&end=m&group=all&header=yes
192.168.10.3 is to replace by the IP address of your iotawatt
This allows me to calculate the energy usage of a particular subcircuit. I have a sensor from the iota for a 3-phases subboard. One of the circuit on this sub-board is using a Shelly 3EM, so to exclude the energy as measured by the shelly I can do something like:
- name: Sub1 kWh
unique_id: sub1_adjusted_kwh
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
state: >
{% set adjustment = 0 %}
{{ states('sensor.iotawatt_sub1_kwh')|float - states('sensor.shelly3em_poolheatpump_channel_a_energy')|float - adjustment }}
It wouldn’t be doable with sensor that resets daily (I’m still puzzled on why someone ever thought it would be a good idea to submit that change)
Maybe this will help some.