Template sensor of goodwe api not showing

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’) }}”

image

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

you mean sensor.sensor_battery_level

1 Like

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

Format your code using the </> button please. You might have indentation errors and we can’t tell.

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') }}"

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.

- 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

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: