Skip to content

5. Home Assistant integration

frtz13 edited this page Dec 10, 2023 · 3 revisions

To interact with the Energy Router, we can set up two Entities in Home Assistant:

  • a Switch to set the Energy Router to automatic mode or manual mode,

  • an Input Number to set the power percentage for manual mode.

You can use the following code in configuration.yaml to define these entities. We also configure a sensor with the (estimated) power sent to the water heater.

input_number:
  energy_router_power:
    name: Energy router manual mode power
    min: 0
    max: 100
    step: 1
    mode: box
    unit_of_measurement: "%"
    icon: mdi:radiator

mqtt:
    sensor:
      - name: "Energy router dimmer"
        state_topic: "home/waterheater-dimmer/power"
        value_template: '{{ value_json.power_estim }}'
        expire_after: 20
        device_class: power
        unit_of_measurement: W

    switch:
      - name: "Energy router mode auto"
        state_topic: "home/waterheater-dimmer/mode"
        value_template: >
          {%- if int(value) == -1 -%}ON{%- else -%}OFF{%- endif -%}
        availability:
          - topic: "home/waterheater-dimmer/RouterLWT"
            payload_available: "online"
            payload_not_available: "offline"
        state_on: "ON"
        state_off: "OFF"
        command_topic: "home/waterheater-dimmer/mode"
        payload_on: -1
        payload_off: 0
        optimistic: false
        qos: 0
        retain: true
        icon: mdi:routes

In case we switch the Energy Router to manual mode, we configure an Automation to send the corresponding payload to its "mode" topic.

alias: Energy router mode to manual
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.energy_router_mode_auto
    from: "on"
    to: "off"
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: mqtt.publish
    data:
      topic: home/waterheater-dimmer/mode
      qos: "0"
      retain: true
      payload: "{{ states.input_number.energy_router_power.state }}"
mode: single

When the Energy Router is in manual mode, and we change the power percentage, we use an Automation to send the new value.

alias: Energy router manual mode power
description: ""
trigger:
  - platform: state
    entity_id:
      - input_number.energy_router_power
condition:
  - condition: state
    entity_id: switch.energy_router_mode_auto
    state: "off"
action:
  - service: mqtt.publish
    data:
      retain: true
      topic: home/waterheater-dimmer/mode
      payload: "{{ trigger.to_state.state }}"
mode: single

To put these controls on our dashboard, you can use the following code:

  - type: horizontal-stack
    cards:
      - type: horizontal-stack
        cards:
          - type: tile
            entity: switch.energy_router_mode_auto
            name: Energy router in automatic mode
          - type: conditional
            conditions:
              - condition: state
                entity: switch.energy_router_mode_auto
                state: 'off'
            card:
              type: tile
              entity: input_number.energy_router_power
              name: Manual mode power
              color: accent

This code will hide the energy_router_power numeric input, when the Energy Router is in automatic mode.

An apex-chart (install via HACS, the Home Assistant Community Store) to track grid power and the power sent to the water heater (in negative direction):

type: custom:apexcharts-card
graph_span: 1h
header:
  show: true
  title: ApexCharts-Card
  show_states: true
  colorize_states: true
series:
  - entity: sensor.house_real_power
    stroke_width: 2
    curve: stepline
    yaxis_id: power
  - entity: sensor.energy_router_dimmer
    stroke_width: 1
    curve: stepline
    yaxis_id: power
    transform: return -x
yaxis:
  - id: power
    opposite: false
    apex_config:
      forceNiceScale: true

Clone this wiki locally