Iotawatt for energy configuration

sensor.Red_Input_1_wh
sensor.Blue_Input_3_wh
sensor.White_Input_2_wh
3phase iotawatt ct inputs above.
These are from my friends Iotawatt. I think he’s reversed them as positive numbers are grid import, negative are grid export. I tried chatgpt to code up something to invert the numbers and then split the positives and negatives (import n export to grid). The furtherest I got on chatgpt was both imp/exp sensors read the same value. Any ideas? Coding isn’t my area. Considering CT’s go negative and positive, I’m unsure why HA only reads positives. Thanks for any help.

- sensor:
      # Red Import Energy (track only positive values)
      name: Red Import Energy Positive
      unique_id: sensor.red_import_positive
      state_class: total_increasing
      unit_of_measurement: "Wh"
      device_class: energy
      state: >
        {% set value = states('sensor.Red_Input_1_wh') | float %}
        {% if states('sensor.Red_Input_1_wh') not in ['unknown', 'unavailable'] %}
          {% if value >= 0 %}
            {{ value }}  # Only positive values for import
          {% else %}
            0  # Ignore negative values (export)
          {% endif %}
        {% else %}
          unavailable
        {% endif %}
      icon: mdi:transmission-tower

  - sensor:
      # Red Export Energy (track only negative values)
      name: Red Export Energy Positive
      unique_id: sensor.red_export_positive
      state_class: total_increasing
      unit_of_measurement: "Wh"
      device_class: energy
      state: >
        {% set value = states('sensor.Red_Input_1_wh') | float %}
        {% if states('sensor.Red_Input_1_wh') not in ['unknown', 'unavailable'] %}
          {% if value < 0 %}
            {{ value | abs }}  # Convert negative to positive for export
          {% else %}
            0  # Ignore positive values (import)
          {% endif %}
        {% else %}
          unavailable
        {% endif %}
      icon: mdi:transmission-tower

  - sensor:
      # Blue Import Energy (track only positive values)
      name: Blue Import Energy Positive
      unique_id: sensor.blue_import_positive
      state_class: total_increasing
      unit_of_measurement: "Wh"
      device_class: energy
      state: >
        {% set value = states('sensor.Blue_Input_3_wh') | float %}
        {% if states('sensor.Blue_Input_3_wh') not in ['unknown', 'unavailable'] %}
          {% if value >= 0 %}
            {{ value }}  # Only positive values for import
          {% else %}
            0  # Ignore negative values (export)
          {% endif %}
        {% else %}
          unavailable
        {% endif %}
      icon: mdi:transmission-tower

  - sensor:
      # Blue Export Energy (track only negative values)
      name: Blue Export Energy Positive
      unique_id: sensor.blue_export_positive
      state_class: total_increasing
      unit_of_measurement: "Wh"
      device_class: energy
      state: >
        {% set value = states('sensor.Blue_Input_3_wh') | float %}
        {% if states('sensor.Blue_Input_3_wh') not in ['unknown', 'unavailable'] %}
          {% if value < 0 %}
            {{ value | abs }}  # Convert negative to positive for export
          {% else %}
            0  # Ignore positive values (import)
          {% endif %}
        {% else %}
          unavailable
        {% endif %}
      icon: mdi:transmission-tower

  - sensor:
      # White Import Energy (track only positive values)
      name: White Import Energy Positive
      unique_id: sensor.white_import_positive
      state_class: total_increasing
      unit_of_measurement: "Wh"
      device_class: energy
      state: >
        {% set value = states('sensor.White_Input_2_wh') | float %}
        {% if states('sensor.White_Input_2_wh') not in ['unknown', 'unavailable'] %}
          {% if value >= 0 %}
            {{ value }}  # Only positive values for import
          {% else %}
            0  # Ignore negative values (export)
          {% endif %}
        {% else %}
          unavailable
        {% endif %}
      icon: mdi:transmission-tower

  - sensor:
      # White Export Energy (track only negative values)
      name: White Export Energy Positive
      unique_id: sensor.white_export_positive
      state_class: total_increasing
      unit_of_measurement: "Wh"
      device_class: energy
      state: >
        {% set value = states('sensor.White_Input_2_wh') | float %}
        {% if states('sensor.White_Input_2_wh') not in ['unknown', 'unavailable'] %}
          {% if value < 0 %}
            {{ value | abs }}  # Convert negative to positive for export
          {% else %}
            0  # Ignore positive values (import)
          {% endif %}
        {% else %}
          unavailable
        {% endif %}
      icon: mdi:transmission-tower

There is a checkbox in the iotawatt for each input that allows you to reverse the CT direction in software.

configGenericInput

1 Like

Yeah getting his ip n user pas for iotawatt now.

Would that code have actually worked ever? I’m guessing reversing will fix some issues

Then do you add the same 3 ct sensors to grid and export or make a export template solar production minus consumption?

Also can’t see web etc cameras through tailscale annoying to try set up. He’s gonna owe me some empire tech cams haha. And you guys some tips. Wish I understood the coding side better.

Can energy dashboard have any negative value? I tried to get 2 sensors for each phase to split the negative or positive, convert to individual positive numbers. The cts will swing negative when consuming on a reverse.

This code gives unavailable.

See: https://www.home-assistant.io/integrations/iotawatt/#configure-iotawatt

No. Production, consumption and return should all be positive values.

1 Like

Made input output sensors on iotawatt.

(Ct min 0) Abs and the other max so hopefully it’s always positive.

Ct sensors are bidirectional. They go negative during grid export usually. One on solar can be unidirectional but you need bidirectional for consumption and export tariffs.

For power devices it isn’t needed but grid entry needs bidirectional. Batteries too.

Ahhh that document had the answer I was looking for , for so long omg. I feel d U m b lol

1 Like