Pour ceux qui veulent le code
j’ai mis ça dans un package appelé beem.yaml
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/1 }}"
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":9,"year":2023}'
# le payload month est a mettre a jour tous les mois pour recuperer les bonnes valeurs.
scan_interval: 30
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\":\"toto@gmail.com\",\"password\":\"mot-de-passe\"}" | 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