Get Sensor from JSON file [ for B-Control Smartmeter EM 300]

I’d like to get a sensor from a json file.

It looks like this: {“serial”:“72081182”,“1-0:1.4.0255":313.5,"1-0:1.8.0255”:20774051,“1-0:2.4.0255":0,"1-0:2.8.0255”:9885390.8,“1-0:3.4.0255":0,"1-0:3.8.0255”:17927351.6,“1-0:4.4.0255":311.7,"1-0:4.8.0255”:14096820.5,“1-0:9.4.0255":442.1,"1-0:9.8.0255”:33725815.8,“1-0:10.4.0255":0,"1-0:10.8.0255”:18349480.8,“1-0:13.4.0255":0.709,"1-0:14.4.0255”:50.004,“1-0:21.4.0255":51.7,"1-0:21.8.0255”:8773681.5,“1-0:22.4.0255":0,"1-0:22.8.0255”:7617323.5,“1-0:23.4.0255":0,"1-0:23.8.0255”:4787230.3,“1-0:24.4.0255":185.4,"1-0:24.8.0255”:7118859,“1-0:29.4.0255":192.5,"1-0:29.8.0255”:12111903.2,“1-0:30.4.0255":0,"1-0:30.8.0255”:10951549.8,“1-0:31.4.0255":0.889,"1-0:32.4.0255”:226.43,“1-0:33.4.0255":0.269,"1-0:41.4.0255”:148.8,“1-0:41.8.0255":13384030.7,"1-0:42.4.0255”:0,“1-0:42.8.0255":4529624.5,"1-0:43.4.0255”:37,“1-0:43.8.0255":9740594.6,"1-0:44.4.0255”:0,“1-0:44.8.0255":2528659.4,"1-0:49.4.0255”:153.3,“1-0:49.8.0255":18610600.6,"1-0:50.4.0255”:0,“1-0:50.8.0255":5339401.4,"1-0:51.4.0255”:0.727,“1-0:52.4.0255":226.582,"1-0:53.4.0255”:0.97,“1-0:61.4.0255":113,"1-0:61.8.0255”:9002235.3,“1-0:62.4.0255":0,"1-0:62.8.0255”:8124340.7,“1-0:63.4.0255":0,"1-0:63.8.0255”:5996727.5,“1-0:64.4.0255":163.4,"1-0:64.8.0255”:7046502.2,“1-0:69.4.0255":198.6,"1-0:69.8.0255”:13480265.9,“1-0:70.4.0255":0,"1-0:70.8.0255”:11024414.5,“1-0:71.4.0255":0.889,"1-0:72.4.0255”:226.05,“1-0:73.4.0*255”:0.569,“status”:0}

I try this, but it does not work:

In the developer tools it is just an empty field.

Any ideas what I am doing wrong?

EDIT: There are actually * symbols before each 255 value, it just does not paste into the forum.

I believe the file has to end with .json (donot ask me why)…cannot check as on the move now. The other thing is that the double quotes donot seem to be good, check this please

“serial”:
which should be
"serial":

While I didn’t correct all of the quote style issues (therefore I removed about half of the data) I did fix enough of them to give you an idea of what you can do.

try pasting this into the developers tools (especially notice the differences between my fixed quotes and your original quotes):

{% set value_json = {"serial":"72081182","1-0:1.4.0255":313.5,"1-0:1.8.0255":20774051,"1-0:2.4.0255":0,"1-0:2.8.0255":9885390.8,"1-0:3.4.0255":0,"1-0:3.8.0255":17927351.6,"1-0:4.4.0255":311.7,"1-0:4.8.0255":14096820.5,"1-0:9.4.0255":442.1,"1-0:9.8.0255":33725815.8,"1-0:10.4.0255":0,"1-0:10.8.0255":18349480.8,"1-0:13.4.0255":0.709,"1-0:14.4.0255":50.004,"1-0:21.4.0255":51.7,"1-0:21.8.0255":8773681.5,"1-0:22.4.0255":0,"1-0:22.8.0255":7617323.5,"1-0:23.4.0255":0,"1-0:23.8.0255":4787230.3,"1-0:24.4.0255":185.4,"1-0:24.8.0255":7118859,"1-0:29.4.0255":192.5,"1-0:29.8.0255":12111903.2,"1-0:30.4.0255":0,"1-0:30.8.0255":10951549.8,"1-0:31.4.0255":0.889,"1-0:32.4.0255":226.43,"1-0:33.4.0255":0.269,"1-0:41.4.0255":148.8,"1-0:41.8.0255":13384030.7,"1-0:42.4.0255":0,"1-0:42.8.0255":4529624.5,"1-0:43.4.0255":37,"1-0:43.8.0255":9740594.6,"1-0:44.4.0255":0,"status":0} %}
{{ value_json['1-0:1.4.0255'] }}

if that’s the actual data that you are getting returned from your web service then I would have to say that the json isn’t properly formatted from the service.

@fritzphantom Please paste code using the </> button, or surrounding with three backticks:

```
CODE HERE
```

That way, you get all of the characters displayed correctly in the forum.

There’s nothing wrong with your value_template: it works for me with @finity’s retyping plus the missing asterisk:

It’s possibly a headers issue. Please try:

value_template: "{{ value[:250] }}"

and paste what is returned, which should be the first 250 characters of the JSON response.

Today I tried again and realized that you have to be logged into the device to be able to access the json link. It worked on my computer because I was logged in another task, but when I logged out I realized it looked like this:

That means I have to figure out how to login first there.

I have found the documentation for the api here.

The process for authentication is described there, but it seems to be quite complicated. Is this somehow doable in home assistant?

EDIT: I figured it out, and added the details below. Hope it helps somebody in the furture.
EDIT2: It would be nice to have this as a HACS addon, does anybody has a hint how to do this best?
EDIT3: updated the entries, there were some errors
EDIT4: the -sensor was missing in templates

It took me a while, but I was able to write a bash script to retrieve the json.

The device is a B-control EM 300.

It looks like this:

#!/bin/bash

# Hardcoded password
PASSWORD="password"

# Define the base URL and the cookie file location
BASE_URL="http://192.168.1.115"
COOKIE_FILE="/tmp/cookie.txt"

# Step 1: Initial GET request to /start.php to get the session cookie and serial
RESPONSE=$(curl -s -X GET "$BASE_URL/start.php" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -c "$COOKIE_FILE")

# Extract the serial from the response using grep and awk
SERIAL=$(echo "$RESPONSE" | grep -o '"serial":"[0-9]*' | awk -F ':"' '{print $2}')

# Step 2: POST request to /start.php to authenticate using the serial as the username
curl -s -X POST "$BASE_URL/start.php" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "login=$SERIAL&password=$PASSWORD" \
     -b "$COOKIE_FILE" \
     -c "$COOKIE_FILE" > /dev/null

# Step 3: Final GET request to /mum-webservice/data.php to retrieve data and clean the response
DATA=$(curl -s -X GET "$BASE_URL/mum-webservice/data.php" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -b "$COOKIE_FILE")

# Remove the trailing '#' from the response if it exists
echo "$DATA" | sed 's/#$//'

Place the password in the script.

I added this script under:
/config/scripts/bcontrol_em300.sh

Important to make it executable:
chmod +x bcontrol_em300.sh

Test it like this:
./bcontrol_em300.sh

The json it returns looks like this:

{"serial":"XXXXXXXXX","1-0:1.4.0*255":3439.2,"1-0:1.8.0*255":20903203.5,"1-0:2.4.0*255":0,"1-0:2.8.0*255":9886005.6,"1-0:3.4.0*255":0,"1-0:3.8.0*255":18001880.4,"1-0:4.4.0*255":787.1,"1-0:4.8.0*255":14142255.3,"1-0:9.4.0*255":3528.1,"1-0:9.8.0*255":33908295.4,"1-0:10.4.0*255":0,"1-0:10.8.0*255":18362501.7,"1-0:13.4.0*255":0.975,"1-0:14.4.0*255":49.977,"1-0:21.4.0*255":3396.2,"1-0:21.8.0*255":8834143.1,"1-0:22.4.0*255":0,"1-0:22.8.0*255":7619529.1,"1-0:23.4.0*255":0,"1-0:23.8.0*255":4808838.1,"1-0:24.4.0*255":465.9,"1-0:24.8.0*255":7141044.8,"1-0:29.4.0*255":3428,"1-0:29.8.0*255":12187909.5,"1-0:30.4.0*255":0,"1-0:30.8.0*255":10962298,"1-0:31.4.0*255":15.414,"1-0:32.4.0*255":222.71,"1-0:33.4.0*255":0.991,"1-0:41.4.0*255":58.8,"1-0:41.8.0*255":13418464.6,"1-0:42.4.0*255":0,"1-0:42.8.0*255":4530593.2,"1-0:43.4.0*255":0,"1-0:43.8.0*255":9768404.1,"1-0:44.4.0*255":120,"1-0:44.8.0*255":2535989.6,"1-0:49.4.0*255":133.6,"1-0:49.8.0*255":18661896.7,"1-0:50.4.0*255":0,"1-0:50.8.0*255":5341396.4,"1-0:51.4.0*255":0.823,"1-0:52.4.0*255":225.811,"1-0:53.4.0*255":0.44,"1-0:61.4.0*255":0,"1-0:61.8.0*255":9041140.1,"1-0:62.4.0*255":15.8,"1-0:62.8.0*255":8126429,"1-0:63.4.0*255":0,"1-0:63.8.0*255":6023640.2,"1-0:64.4.0*255":201.2,"1-0:64.8.0*255":7064222.1,"1-0:69.4.0*255":0,"1-0:69.8.0*255":13536996,"1-0:70.4.0*255":201.9,"1-0:70.8.0*255":11033267.8,"1-0:71.4.0*255":0.942,"1-0:72.4.0*255":225.252,"1-0:73.4.0*255":-0.079,"status":0}

Now I am looking for a way to get all the json values as sensors, and also remap the name fields to something more meaningful. I manage to do it for one, but since there are many values I don’t want to curl the file for each value, but parse all with one update.

Does somebody has an idea how to do that?

In the configuration.yaml I added the script as a command_line sensor like this:

command_line:
  - sensor:
      name: "bcontrol_em300_data"
      command: "/bin/bash /config/scripts/bcontrol_em300.sh"
      scan_interval: 60  # Adjust based on how often you want to call the script (in seconds)
      value_template: "{{ value_json['status'] }}"
      json_attributes:
        - "1-0:1.4.0*255"
        - "1-0:1.8.0*255"
        - "1-0:2.4.0*255"
        - "1-0:2.8.0*255"
        - "1-0:3.4.0*255"
        - "1-0:3.8.0*255"
        - "1-0:4.4.0*255"
        - "1-0:4.8.0*255"
        - "1-0:9.4.0*255"
        - "1-0:9.8.0*255"
        - "1-0:10.4.0*255"
        - "1-0:10.8.0*255"
        - "1-0:13.4.0*255"
        - "1-0:14.4.0*255"
        - "1-0:21.4.0*255"
        - "1-0:21.8.0*255"
        - "1-0:22.4.0*255"
        - "1-0:22.8.0*255"
        - "1-0:23.4.0*255"
        - "1-0:23.8.0*255"
        - "1-0:24.4.0*255"
        - "1-0:24.8.0*255"
        - "1-0:29.4.0*255"
        - "1-0:29.8.0*255"
        - "1-0:30.4.0*255"
        - "1-0:30.8.0*255"
        - "1-0:31.4.0*255"
        - "1-0:32.4.0*255"
        - "1-0:33.4.0*255"
        - "1-0:41.4.0*255"
        - "1-0:41.8.0*255"
        - "1-0:42.4.0*255"
        - "1-0:42.8.0*255"
        - "1-0:43.4.0*255"
        - "1-0:43.8.0*255"
        - "1-0:44.4.0*255"
        - "1-0:44.8.0*255"
        - "1-0:49.4.0*255"
        - "1-0:49.8.0*255"
        - "1-0:50.4.0*255"
        - "1-0:50.8.0*255"
        - "1-0:51.4.0*255"
        - "1-0:52.4.0*255"
        - "1-0:53.4.0*255"
        - "1-0:61.4.0*255"
        - "1-0:61.8.0*255"
        - "1-0:62.4.0*255"
        - "1-0:62.8.0*255"
        - "1-0:63.4.0*255"
        - "1-0:63.8.0*255"
        - "1-0:64.4.0*255"
        - "1-0:64.8.0*255"
        - "1-0:69.4.0*255"
        - "1-0:69.8.0*255"
        - "1-0:70.4.0*255"
        - "1-0:70.8.0*255"
        - "1-0:71.4.0*255"
        - "1-0:72.4.0*255"
        - "1-0:73.4.0*255"
        - "status"

template:
  - sensor:
    - name: "BControlEM300 Active Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:1.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 Active Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:1.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 Active Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:2.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 Active Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:2.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 Reactive Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:3.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 Reactive Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:3.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 Reactive Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:4.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 Reactive Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:4.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 Apparent Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:9.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 Apparent Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:9.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 Apparent Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:10.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 Apparent Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:10.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 Power Factor"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:13.4.0*255') | float }}"
      unit_of_measurement: ""
      device_class: "power_factor"
    - name: "BControlEM300 Frequency"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:14.4.0*255') | float }}"
      unit_of_measurement: "Hz"
      device_class: "frequency"
    - name: "BControlEM300 L1 Active Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:21.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 L1 Active Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:21.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 L1 Active Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:22.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 L1 Active Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:22.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 L1 Reactive Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:23.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 L1 Reactive Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:23.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 L1 Reactive Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:24.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 L1 Reactive Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:24.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 L1 Apparent Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:29.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 L1 Apparent Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:29.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 L1 Apparent Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:30.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 L1 Apparent Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:30.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 L1 Current"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:31.4.0*255') | float }}"
      unit_of_measurement: "A"
      device_class: "current"
    - name: "BControlEM300 L1 Voltage"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:32.4.0*255') | float }}"
      unit_of_measurement: "V"
      device_class: "voltage"
    - name: "BControlEM300 L1 Power Factor"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:33.4.0*255') | float }}"
      unit_of_measurement: ""
      device_class: "power_factor"
    - name: "BControlEM300 L2 Active Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:41.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 L2 Active Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:41.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 L2 Active Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:42.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 L2 Active Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:42.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 L2 Reactive Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:43.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 L2 Reactive Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:43.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 L2 Reactive Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:44.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 L2 Reactive Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:44.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 L2 Apparent Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:49.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 L2 Apparent Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:49.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 L2 Apparent Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:50.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 L2 Apparent Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:50.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 L2 Current"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:51.4.0*255') | float }}"
      unit_of_measurement: "A"
      device_class: "current"
    - name: "BControlEM300 L2 Voltage"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:52.4.0*255') | float }}"
      unit_of_measurement: "V"
      device_class: "voltage"
    - name: "BControlEM300 L2 Power Factor"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:53.4.0*255') | float }}"
      unit_of_measurement: ""
      device_class: "power_factor"
    - name: "BControlEM300 L3 Active Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:61.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 L3 Active Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:61.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 L3 Active Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:62.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
    - name: "BControlEM300 L3 Active Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:62.8.0*255') | float }}"
      unit_of_measurement: "Wh"
      device_class: "energy"
    - name: "BControlEM300 L3 Reactive Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:63.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 L3 Reactive Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:63.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 L3 Reactive Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:64.4.0*255') | float }}"
      unit_of_measurement: "var"
      device_class: "power"
    - name: "BControlEM300 L3 Reactive Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:64.8.0*255') | float }}"
      unit_of_measurement: "varh"
      device_class: "energy"
    - name: "BControlEM300 L3 Apparent Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:69.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 L3 Apparent Energy Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:69.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 L3 Apparent Power Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:70.4.0*255') | float }}"
      unit_of_measurement: "VA"
      device_class: "power"
    - name: "BControlEM300 L3 Apparent Energy Minus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:70.8.0*255') | float }}"
      unit_of_measurement: "VAh"
      device_class: "energy"
    - name: "BControlEM300 L3 Current"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:71.4.0*255') | float }}"
      unit_of_measurement: "A"
      device_class: "current"
    - name: "BControlEM300 L3 Voltage"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:72.4.0*255') | float }}"
      unit_of_measurement: "V"
      device_class: "voltage"
    - name: "BControlEM300 L3 Power Factor"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:73.4.0*255') | float }}"
      unit_of_measurement: ""
      device_class: "power_factor"


After a reboot go to overview, all the values should be visible there and are also usable in home assistant now!

Hi, your script works great! I made a small change to get it running: I added the sensor: line before name.

template:
    sensor:
    - name: "BControlEM300 Active Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:1.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"

Glad it is useful for someone else! Good you managed to fix the error your self, I updated it above.

To make it easier for someone else to find, I would change the subject as well.

added a unique ID as ell the state_class to the code on my side.

template:
    sensor:
    - name: "BControlEM300 Active Power Plus"
      state: "{{ state_attr('sensor.bcontrol_em300_data', '1-0:1.4.0*255') | float }}"
      unit_of_measurement: "W"
      device_class: "power"
      state_class: measurement
      unique_id: 'BControlEM300-Active-Power-Plus'