neon.ninja

Sharing enlightening moments of home automation

Electricity consumption and production

When I got my solar system, it came with a little box, Envoy-S, that communicates with the micro-inverters on the roof, aggregates the data and sends it together with the electricity consumption data into the cloud.

Monitoring my solar system

But luckily the device also comes with a simple local web interface, and provides its comprehensive data collection in JSON format. Overall electricity production and consumption data is available, and it appears that it could also report on a connected battery.

Envoy-S in a weather-proof box near my electricity meter

Configuration in Home Assistant

The attribute names are fairly self-descriptive, and an integrations using the rest sensor is pretty straightforward. The Envoy-S box does not require authentication, i.e. you would only need to replace ENVOY-IP-ADDRESS with your box’s actual IP address.

sensor:
  # Envoy Integrated Meter - Production
  - platform: rest
    name: Envoy Production Integrated Meter - Lifetime
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.production[1].whLifetime) }}'
    method: GET
    unit_of_measurement: "Wh"
  - platform: rest
    name: Envoy Production Integrated Meter - Last Seven Days
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.production[1].whLastSevenDays) }}'
    method: GET
    unit_of_measurement: "Wh"
  - platform: rest
    name: Envoy Production Integrated Meter - Today
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.production[1].whToday) }}'
    method: GET
    unit_of_measurement: "Wh"
  - platform: rest
    name: Envoy Production Integrated Meter - Now
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.production[1].wNow) }}'
    method: GET
    unit_of_measurement: "W"
  # Envoy Integrated Meter - Total Consumption
  - platform: rest
    name: Envoy Consumption Integrated Meter - Lifetime
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.consumption[0].whLifetime) }}'
    method: GET
    unit_of_measurement: "Wh"
  - platform: rest
    name: Envoy Consumption Integrated Meter - Last Seven Days
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.consumption[0].whLastSevenDays) }}'
    method: GET
    unit_of_measurement: "Wh"
  - platform: rest
    name: Envoy Consumption Integrated Meter - Today
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.consumption[0].whToday) }}'
    method: GET
    unit_of_measurement: "Wh"
  - platform: rest
    name: Envoy Consumption Integrated Meter - Now
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.consumption[0].wNow) }}'
    method: GET
    unit_of_measurement: "W"
  # Envoy Integrated Meter - Net Consumption
  - platform: rest
    name: Net Consumption - Now
    resource: http://ENVOY-IP-ADDRESS/production.json
    value_template: '{{ "%.1f" | format(value_json.consumption[1].wNow) }}'
    method: GET
    unit_of_measurement: "W"
Home Assistant electricity production and consumption data from Envoy-S

All that information is quite helpful and can be used for all sorts of purposes, but personally I found the current net consumption probably the most useful information since that tells me if – at the moment – I am producing more electricity than I use and hence indicates if I should turn another appliance on or wait a bit.

Since the net consumption is a numeric value – positive number if consuming more than producing, and negative number if producing more than consuming – I created binary sensors to display the current state more prominently. I could combine both states into one sensor, but unfortunately Home Assistant’s binary sensor do not support custom icons for the different states at the moment. So, in the meantime I created two binary sensors:

binary_sensor:
  - platform: template
    sensors:
      power_importing:
        value_template: '{{ (states.sensor.net_consumption__now.state | float) > 0}}'
        friendly_name: 'Importing'
      power_exporting:
        value_template: '{{ (states.sensor.net_consumption__now.state | float) <= 0}}'
        friendly_name: 'Exporting'

Presenting the state in HADashboard

I configured two widgets on my dashboard that show the current state – one showing the actual numeric net consumption value and one indicating with a large coloured icon whether I am importing electricity from the grid or exporting to the grid.

energy_net_consumption:
  widget_type: sensor
  title: Net Consumption
  units: "W"
  precision: 0
   entity: sensor.net_consumption__now
energy_import_export:
  widget_type: binary_sensor
  title: Electricity
  icon_on: mdi-arrow-down-box
  icon_style_active: "color: red; font-size: 400%; top: 35px"
  icon_off: mdi-arrow-up-box
  icon_style_inactive: "color: green; font-size: 400%; top: 35px"
  state_text: 1
  state_map:
    "on": Importing Grid
    "off": Exporting Solar
  entity: binary_sensor.power_importing
HADashboard widgets showing current electricity consumption information

In the long term I would like to combine the two into one widget that displays the absolute value (i.e. always a positive number) together with an icon.

Update 03 Feb 2019

Luckily in the meantime Home Assistant has got a dedicated Enphase Envoy sensor built in, so I decided to give up my custom rest sensor based integration described above. The new sensor is working very well and is internally based on the same approach to retrieve the data directly from the Envoy device via JSON.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *