EnergySensor for grid consumption

Hello,

I have a Rest API Sensor, for EnergyData.
The Integration is spliced into a sensor:

platform: rest
name: "Energy Data"
resource: http://10.0.0.157/rest
method: GET
scan_interval: 1 # Update interval
headers:
  accept: "application/json"
json_attributes:
  - "1.8.0"
  - "2.8.0"
  - "3.8.1"
  - "4.8.1"
  - "1.7.0"
  - "2.7.0"
  - "3.7.0"
  - "4.7.0"
  - "1.128.0"
  - "saldo"
value_template: "{{ value_json.saldo }}"

i can see the sensor in home assistant

then i created a template for a sensor

sensor:
  - name: "Amis_Energy_Sensor_1.7.0"
    unique_id: AmisEnergySensor1.7.0
    state_class: total_increasing
    unit_of_measurement: kWh
    device_class: energy
    state: "{{ state_attr('sensor.energy_data', '1.7.0') | float / 1000 }}"

I can add this sensor into my Dashboard, but i cannot use it for Energy Grid
Consumption. But the Template has all the relevant properties like
state_class, unit_of_Measurement and device_class.

How to get it into the Grid Consumption?

Go to Developer Tools → Statistics and see if there is a FIX ISSUE button to the right of your sensor.

There are a couple of optional improvements you can make:

  1. You do not need to use underscores in names. The name option can take spaces and may look better on your dashboard. e.g.
sensor:
  - name: "Amis Energy Sensor 1.7.0" 
  1. A one second scan interval is not needed for total sensors and is just spamming your resource. Set it to something sensible like 10 seconds minimum.

  2. If you use the rest integration, rather than the rest sensor platform, you can create all the sensors with one call to the resource and without the need for extra template sensors.

e.g.

### configuration.yaml ###

rest:
  - resource: http://10.0.0.157/rest
    scan_interval: 10
    headers:
      accept: "application/json"
    sensor:
      - name: "Energy Data"
        value_template: "{{ value_json.saldo }}"

      - name: "Amis Energy Sensor 1.7.0"
        unique_id: AmisEnergySensor_1_7_0
        state_class: total_increasing
        unit_of_measurement: kWh
        device_class: energy
        state: "{{ value_json['1.7.0'] | float / 1000 }}"

      - name: "Amis Energy Sensor 1.8.0"
        unique_id: AmisEnergySensor_1_8_0
        state_class: total_increasing
        unit_of_measurement: kWh
        device_class: energy
        state: "{{ value_json['1.8.0'] | float / 1000 }}"

      - name: "Amis Energy Sensor 2.8.0"
        unique_id: AmisEnergySensor_2_8_0
        state_class: total_increasing
        unit_of_measurement: kWh
        device_class: energy
        state: "{{ value_json['2.8.0'] | float / 1000 }}"

      - name: etc...

Hello @tom_l,

wow, many thanks, this is workin awsome.

Many thanks
Daniel

1 Like