Adding solar and wall charger data via client REST API

Dear,

I have an energy monitor (CEMM) that provides me data over a local API.
Now I want to use this values in my energy dashboard in HA.
For example, my solar output :
http://192.168.1.142/open-api/v1/mb2/realtime/
Gives me the result :

{"data":{"t1":[1641377395000,7906.34],"t2":[0,0],"electric_power":[1641377395000,908.3]},"totals":{"t1":[1641377404000,5633.71],"t2":[1641377404000,2272.62],"electric_energy":[1641377404000,5625.71],"electric_energy_high":[1641377404000,2245.38],"t3":[1641377404000,8],"t4":[1641377404000,27.24]}}

Where the value of T1 after the comma, is the value I need (in this case 7906.34) also a value for my SOLAR readings, it’s the overall power generated since the beginning (kwh).

Same for my car charger.
call : http://192.168.1.142/open-api/v1/mb3/realtime/
results in :

{"data":{"t1":[1641378664000,4259],"t2":[0,0],"t3":[1641378664000,0],"t4":[0,0],"electric_power":[1641378664000,7.2]},"totals":{"t1":[1641378667000,2526.85],"t2":[1641378667000,1732.15],"t3":[1641378667000,0],"t4":[1641378667000,0],"electric_energy":[1641378667000,2526.85],"electric_energy_high":[1641378667000,1732.15]}}

Where t1 is the TOTAL amount of energy (kwh) used by the charger.

How can I integrate this in my energy dashboard, and where ? I’m just starting to use HA, so I’m new to the YAML config

Erwin

Use a restful sensor.

For the first example:

rest:
  - resource: http://192.168.1.142/open-api/v1/mb3/realtime/
    sensor:
      - name: "Solar Energy"
        value_template: "{{ value_json.data.t1[1] }}"
        unit_of_measurement: "kWh" 
        state_class: measurement
        device_class: energy

You should then be able to add this to the energy dashboard.

Likewise for the second.

OK, I added this to my config :

rest :
  - resource: http://192.168.1.142/open-api/v1/mb3/realtime/
    method: GET
    sensor :
      name: "Stroomverbruik Laadpaal"
      value_template: '{{ value_json["data"].t1[1] | round(2) | float }}'
      device_class: energy
      state_class: measurement
      unit_of_measurement: kWh

  - resource: http://192.168.1.142/open-api/v1/mb2/realtime/
    method: GET
    sensor :
      name: "Opbrengst Zon"
      value_template: '{{ value_json["data"].t1[1] | round(2) | float }}'
      device_class: energy
      state_class: measurement
      unit_of_measurement: kWh

Does this look correct ?
because then I get this error :

Logger: homeassistant.components.rest.data
Source: components/rest/data.py:74
Integration: RESTful (documentation, issues)
First occurred: 13:00:46 (2 occurrences)
Last logged: 13:01:01

Error fetching data: http://192.168.1.142/open-api/v1/mb3/realtime/ failed with
Error fetching data: http://192.168.1.142/open-api/v1/mb2/realtime/ failed with

Try this

value_template: '{{ value_json["data"]["t1"][1] | float(0) | round(2) }}'

or this

value_template: '{{ value_json.data.t1[1] | float(0) | round(2) }}'

Also do you need to supply any sort of authentication to your energy monitor api when querying it?

I can see only the 2nd sensor :
image

And it looks like it’s working, but I can’t see it in the energy dashboard (does it need some extra info to see it as solar production ?)
image

And the wall charger is not visible at all.

Erwin

Oh shoot. I dun goofed.

This:

state_class: measurement

Should be:

state_class: total_increasing

Otherwise it won’t show in the Energy Dashboard.

Show your config for the non working sensor and some example data.

I managed to get it working, with the overall values (kWh), and the realtime (W),
Realtime : device_class set as power, and in W, overall set as ‘energy’ and in kWh. This is my config, for those who want to know :

rest :
  - resource: http://192.168.1.142/open-api/v1/mb3/realtime/
    method: GET
    sensor :
      name: "Laadpaal (tot)"
      value_template: '{{ value_json.data.t1[1] | float(0) | round(2) }}'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      
  - resource: http://192.168.1.142/open-api/v1/mb3/realtime/
    method: GET
    sensor :
      name: "Laadpaal"
      value_template: '{{ value_json.data.electric_power[1] | float(0) | round(0) }}'
      device_class: power
      state_class: measurement
      unit_of_measurement: W

  - resource: http://192.168.1.142/open-api/v1/mb2/realtime/
    method: GET
    sensor :
      name: "Zonnepanelen (tot)"
      value_template: '{{ value_json.data.t1[1] | float(0) | round(2) }}'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: kWh
      
  - resource: http://192.168.1.142/open-api/v1/mb2/realtime/
    method: GET
    sensor :
      name: "Zonnepanelen"
      value_template: '{{ value_json.data.electric_power[1] | float(0) | round(0) }}'
      device_class: power
      state_class: measurement
      unit_of_measurement: W

I’ve been working on a core integration for CEMM for a while, but I still run into quite a few problems because their API is built so modularly. Hope to be able to finish it soon.

With my solution above, i’m able to read all the needed info. But I know they are working on a complete new frontend (backend I don’t know), so it’s possible that will change soon…

Hi

I am also working on CEMM (using the local API)

I have trouble getting the sensor “UL1” working, see my configuration.yaml below.

from the url (local): “http://192.168.86.42/api/v3/data/realtime/36864_1_5” i get this result:

[{“channel”:“36864_1_5”,“direction”:“input”,“value”:“232”,“time_updated”:“1648751522.1029”,“time”:“1648751522.1029”}]

The “value” i would like from the url is “232” (on the url this value is updating every 5 sec)

#CEMM
rest:

Any suggestions?

1 Like

Try this :

value_template: ‘{{ value_json.[0].value | float(0) | round(0) }}’

Found the path with : https://jsonpathfinder.com/

@Roger85 is this working now?