Hi, I just want to share with you my configuration for getting the generated power from my Beem Solar panels.
Since there is no local API, alas, I configured a sensor that get the generated power through their (unexposed) remote API.
template:
- sensor:
- name: post_data
state: '{"month":{{now().strftime("%m").lstrip("0")}},"year":{{now().strftime("%Y")}}}'
sensor:
- platform: command_line
command: "curl -X POST -H --location 'https://api-x.beem.energy/beemapp/box/summary' --header 'authorization: Bearer ********************' --header 'content-type: application/json; charset=UTF-8' --header 'Accept: */*' --data '{{ states('sensor.post_data') }}'"
name: "Solar Power"
scan_interval: 60
value_template: "{{ value_json[0].wattHour }}"
unit_of_measurement: W
unique_id: "Solar Power"
You can get your bearer token inspecting with Chrome their website (a web app in Dart I think): Beem Energy . As for now there is no exposed API and no exposed methos to get the bearer token.
In the API usage youâll find the POST Iâm using above.
1 Like
hi jimbolimbo3,
Thanks a lot for this post, he save me from a big headache I have had since few days. I was struggling with RESTful, Command Line, Template, single or double Quotes, Payload, etcâŠ
I learn a lot but did not succeed.
I made some modifications :
sensor:
- platform: command_line
command: 'token=$(curl https://api-x.beem.energy/beemapp/user/login -X POST -H "Content-Type: application/json" --data-raw "{\"email\":\"%email%\",\"password\":\"%password%\"}" | jq .accessToken) && token=${token//\"} && echo $token'
name: beem_token
scan_interval: 3600
- platform: command_line
command: "curl -X POST -H --location 'https://api-x.beem.energy/beemapp/box/summary' --header 'authorization: Bearer '{{ states('sensor.beem_token') }}'' --header 'content-type: application/json; charset=UTF-8' --header 'Accept: */*' --data '{{ states('sensor.post_data') }}'"
name: total_month
scan_interval: 60
value_template: "{{ value_json[0].totalMonth|float/1000 }}"
unit_of_measurement: kWh
- platform: command_line
command: "curl -X POST -H --location 'https://api-x.beem.energy/beemapp/box/summary' --header 'authorization: Bearer '{{ states('sensor.beem_token') }}'' --header 'content-type: application/json; charset=UTF-8' --header 'Accept: */*' --data '{{ states('sensor.post_data') }}'"
name: total_day
scan_interval: 60
value_template: "{{ value_json[0].totalDay|float/1000 }}"
unit_of_measurement: kWh
- platform: command_line
command: "curl -X POST -H --location 'https://api-x.beem.energy/beemapp/box/summary' --header 'authorization: Bearer '{{ states('sensor.beem_token') }}'' --header 'content-type: application/json; charset=UTF-8' --header 'Accept: */*' --data '{{ states('sensor.post_data') }}'"
name: watt_hour
scan_interval: 60
value_template: "{{ value_json[0].wattHour|float/1000 }}"
unit_of_measurement: kWh
first sensor will retrieve the token, you just have to replace %email% and %passsword% with your login and password. He will update the token every hour (I donât know if it is necessary or not)
the next three will retrieve your data from your beem solar panels in kWh.
thank for your help
1 Like
Hello, i canât connect with my credentials, the beem_token is permanently null⊠It works always or itâs finished?
Any ideas?
And how use this measurement with energy dashboard?
Thanks!
Hello,
in this exact moment it is still working for me. Try to get the token using the website and then use the beem_token sensor. Let me know if it works.
hello @Iceblue256 ,
still working for me.
did you try to connect with this address: Beem Energy in your web brower ?
One advice/clue : my password doesnt contain any special character.
did you test to obtain your token within a terminal ? you can use the module SSH & Web terminal.
I didnt find a solution to integrate in energy dashboard. i have the message : Entity not defined.
mathuieu
(Mathieu Quienne)
May 26, 2023, 1:16pm
6
Hello @malendure ,
thanks for the sharing i use your code and itâs now very well working,
even with specials caracters in the password !
i had some problems to use your code because of a typo :
a backslash is missing after the email before the quote :
{\"email\":\"%email%\",\"password\":\"%password%\"}
hope this will help others finding this post !
mathuieu
(Mathieu Quienne)
May 26, 2023, 1:18pm
7
Hello,
can you check you donât missed the backslash at the end of the email ?
{\"email\":\"%email%",\"password\":\"%password%\"}
mc59
May 27, 2023, 4:55pm
8
Hello,
everything seems ok, except for the post data : {{ states(âsensor.post_dataâ) }}
where do you set it ?
if i replace it with {âmonthâ: 5,âyearâ: 2023}, i get a response, otherwise a 400 error code
thanks for help
mathuieu
(Mathieu Quienne)
May 30, 2023, 10:50am
9
If you took the code from Malendure, you should also add the first paragraph of jimbo to define post_data:
template:
- sensor:
- name: post_data
state: '{"month":{{now().strftime("%m").lstrip("0")}},"year":{{now().strftime("%Y")}}}'
hello @mc59 and @mathuieu ,
Iâm happy that this is useful.
I did change a bit to be able to use the sensor in Energy dashboard.
template:
- sensor:
- name: post_data
state: '{"month":{{now().strftime("%m").lstrip("0")}},"year":{{now().strftime("%Y")}}}'
- name: total_month
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: "{{ state_attr('sensor.beem','totalMonth') | float/1000 }}"
icon: mdi:solar-power
- name: total_day
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
state: "{{ state_attr('sensor.beem','totalDay') | float/1000 }}"
icon: mdi:solar-power
- name: watt_hour
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
state: "{{ state_attr('sensor.beem','wattHour') | float/1000 }}"
icon: mdi:solar-power
rest:
- resource_template: https://api-x.beem.energy/beemapp/box/summary
method: POST
headers:
Content-type: application/json
Authorization: !secret beem_token
payload: '{"month":6,"year":2023}'
scan_interval: 60
sensor:
- name: "beem"
json_attributes_path: "$[0]"
json_attributes:
- "totalMonth"
- "wattHour"
- "totalDay"
value_template: 'OK'
command_line:
- sensor:
command: 'token=$(curl https://api-x.beem.energy/beemapp/user/login -X POST -H "Content-Type: application/json" --data-raw "{\"email\":\"email\",\"password\":\"password\"}" | jq .accessToken) && token=${token//\"} && echo $token && sed -i "s/\(beem_token:\)\(.*\)/\1 Bearer $token/" /config/secrets.yaml'
name: beem_token
scan_interval: 84600
shell_command:
beem: sed -i "s/\({{cmd}}:\)\(.*\)/\1 '{{ states.sensor.post_data.state|to_json }}'/" /config/configuration.yaml
the hard part was to update the payload every month wihout having to modify manually the config.yaml each time. the only way I found was to create an automation to execute the beem shell command.
alias: beem payload
description: ""
trigger:
- platform: time
at: "00:00:01"
condition:
- condition: template
value_template: "{{ now().day == 1 }}"
action:
- service: shell_command.beem
data:
cmd: payload
- service: homeassistant.restart
data: {}
mode: single
enjoy
mathuieu
(Mathieu Quienne)
June 5, 2023, 2:37pm
12
Hello @malendure ,
thanks for the sharing,
i tried to add this new code but i get the error :
Error loading /config/configuration.yaml: Secret beem_token not defined
i then tried to use the beem_token sensor from the last extract but itâs not working.
where do you define your token in this new version ?
(when it will be working iâll use a dedicated package configuration file to clean my config.yaml)
mathuieu
(Mathieu Quienne)
June 5, 2023, 3:24pm
13
i discovered the secrets.yaml file !
after adding manually the token in this file, the error is gone.
but the values are unavaliable, i should have missed somethingâŠ
hello @mathuieu ,
yes sorry I forgot, I corrected my post.
yes I create a sensor to retrieve my token and store it in the secret.yaml.
it should work now
1 Like
mathuieu
(Mathieu Quienne)
June 6, 2023, 8:13am
15
Thanks,
the secret is well set now,
after a reboot everything is working !
i added total_day to the energy dashboard, nice!
thanks again for your work and the sharing !
1 Like
Xerses
July 27, 2023, 8:11pm
16
Hi everyone,
I tried to user that code but everytime I execute the shell_command, it completely destroys my configuration.yaml by adding â{âmonthâ:7,âyearâ:2023}â everywhere.
Do i miss something ? I just copy-paste everything and just changed the email and password values (my password has a â/â in it, maybe thatâs the problem ?
Also @mathuieu , how did you add the total_day to Energy dashboard ?
Thanks for your help.
mathuieu
(Mathieu Quienne)
July 28, 2023, 7:54am
17
Hi Xerses,
in the energy dashboard config page (/config/energy),
you just have to add the sensor as a solar production value :
for the automation, i didnât implemented it yet, i change manually the value each month
Hello @Xerses ,
No issue with the automtion since 2 month : his role is to replace only the payload in a json format. It does not need your password.
In your case, this means that you donât copy exactly either the automation or the shell_command. Space are also important.
My password does not contains special character, only number and letter. With your special character, do you test the command to obtain your token?
Post your code if it still doesnât work.
See ya
mathuieu
(Mathieu Quienne)
August 21, 2023, 1:28pm
19
Hello,
i just finished installing Open DTU on a ESP32 board with a NRF24L01+ radio board
and itâs a really better way to get live stats directly from the inverter.
data are locally managed and donât on Beem servers.
not a electronic specialist but i finally managed to flash correctly the board following the tutorial,
for less than 10⏠itâs worthy !
choose one with an external antenna to get better transmission.
Hello there,
I get this error: UndefinedError: âvalue_jsonâ is undefined