TheAnT1979
(The An T1979)
January 11, 2023, 8:06pm
1
Hello,
i’m new to HA and i’m trying to get the battery status from goodwe API.
i created a template sensor but is not showing up after restart.
platform: template
sensors:
sensor_battery_level:
friendly_name: “Battery Level”
unique_id: “battery level”
unit_of_measurement: ‘%’
state: “{{ state_attr(‘sensor.inverter_oostende_vandenberghe’,‘soc’) }}”
please some advice
platform: template
sensors:
sensor_battery_level:
friendly_name: "Battery Level"
unique_id: "battery_level"
unit_of_measurement: "%"
state: "{{ state_attr('sensor.inverter_oostende_vandenberghe','soc') }}"
Your new sensor has a name : sensor.battery_level
petro
(Petro)
January 11, 2023, 10:09pm
3
you mean sensor.sensor_battery_level
1 Like
TheAnT1979
(The An T1979)
January 12, 2023, 11:15am
4
i changed it to
Blockquote- platform: template
sensors:
sensor.sensor_battery_level:
friendly_name: “Battery Level BYD”
unique_id: “battery level byd”
unit_of_measurement: ‘%’
state: “{{ state_attr(‘sensor.inverter_oostende_vandenberghe’,‘soc’) }}”
Blockquote
after restart , sensor does not show up…
tried it then like this:
still no luck
Troon
(Troon)
January 12, 2023, 11:59am
5
Format your code using the </> button please. You might have indentation errors and we can’t tell.
TheAnT1979
(The An T1979)
January 12, 2023, 12:05pm
6
sensor:
- template:
sensors:
battery_byd_power
friendly_name:'Battery BYD'
unit_of_measurement:'%'
device_class:power
value_template:"{{ state_attr('sensor.inverter_oostende_vandenberghe','soc') }}"
Troon
(Troon)
January 13, 2023, 10:08am
7
Feels like you’re just making this up rather than using the documentation…
What you have is closest to the legacy format (docs ) — here it is fixed:
sensor:
- platform: template
sensors:
battery_byd_power:
friendly_name: 'Battery BYD'
unit_of_measurement: '%'
device_class: power
value_template: "{{ state_attr('sensor.inverter_oostende_vandenberghe','soc') }}"
…but you should use the modern format (docs ):
template:
- sensor:
- name: "Battery BYD"
unique_id: b3067312-5ede-48aa-af16-6271a1272a60
unit_of_measurement: '%'
device_class: battery
state: "{{ state_attr('sensor.inverter_oostende_vandenberghe','soc') }}"
I’ve included an optional but good-practice unique_id
— just needs to be a random string, and I use this tool to generate them.
Also (and I’ve only changed it in the modern format) if this is a battery state of charge measurement in %, you should use device_class: battery
(docs ). It’s not a measurement of power, but of energy.
TheAnT1979
(The An T1979)
January 13, 2023, 2:36pm
8
- platform: template
sensors:
battery_byd_level:
friendly_name: "Battery Byd Level"
unit_of_measurement: '%'
icon_template: mdi:battery-high
value_template: "{{ state_attr('sensor.inverter_oostende_vandenberghe','soc') }}"
this works for me
1 Like
Troon
(Troon)
January 13, 2023, 2:45pm
9
If you give it device_class: battery
and remove the icon_template
then the icon will be automatically adjusted to show the correct level. Look: