Trying to get my battery % into homekit

I am trying to get my solar battery level to display in the Home app for my other half.

I have created some template sensors i can get it to show up as humidity but its a hassle to get it to display. I also tried a battery sensor but that adds it if i click on a tile for the deye/sunsynk then settings (it shows battery in there). What’s the best way to get a tile that shows the battery %

#### Template sensor ######
sensor:
  - platform: template
    sensors:
      weather_calc_humidity:
        device_class: humidity
        friendly_name: "Outside Humidity"
        unit_of_measurement: "%"
        value_template: "{{ states('sensor.deye_sunsynk_sol_ark_battery_state_of_charge') }}"
  
  - platform: template
    sensors:
      battery_charge_homekit:
        device_class: battery
        friendly_name: "Battery State of Charge for HomeKit"
        value_template: "{{ states('sensor.deye_sunsynk_sol_ark_battery_state_of_charge') | float }}"
        unit_of_measurement: "%"





    
####### Homekit #######
homekit:
  filter:
    include_domains:
      #- light
      #- sensor
    include_entities:
      - sensor.battery_charge_homekit
      - sensor.weather_calc_humidity

You must mark the YAML up as code here in the forum, otherwise the indentation will be broken and it is impossible for anyone to correctly interpret the code.

But start by reading the HomeKit Bridge documentation. It explicitly lists configuration variables linked_battery_sensor and low_battery_threshold for your purpose.

Also I wouldn’t expect your first sensor to work, as your value_template returns a string when a number is expected. You need to cast the output of states to a float or int, as you already do in the second sensor.

Thank you for your reply sorry i fixed the code. I am not a expert in code just muddling along but getting there (with chatgpt help)

I did read the homekit docs and i did not want a linked battery (which is what i believe has happened in the second example). I just want tile that she can see (much like a lamp one that says 100% etc but the battery %).

Thank you for your time and hope i make sense

That would be impossible as I am pretty sure there is no HomeKit battery device type, it is only intended to ever be a device attribute.

If you are dead set on having it as a tile in HomeKit you would have to make something like a battery entity that pretends to be a light.

Thanks i did consider light when i typed it.

In case anyone else reads this. I now have a light in homekit that shows my battery %

light:
  - platform: template
    lights:
      battery_charge_light:
        friendly_name: "Battery Charge as Light"
        value_template: >
          {{ states('sensor.deye_sunsynk_sol_ark_battery_state_of_charge') | float > 0 }}
        level_template: >
          {% set charge = states('sensor.deye_sunsynk_sol_ark_battery_state_of_charge') | float %}
          {{ (charge * 2.55) | int if charge >= 0 else 0 }}
        turn_on:
          service: script.no_op  # Dummy turn-on action
        turn_off:
          service: script.no_op  # Dummy turn-off action
        set_level:
          service:

then i added this to my scripts

no_op:
  alias: No Operation
  sequence: []

Does it not work to merely use an empty dict for turn_on / turn_off / set_level?

light:
  - platform: template
    lights:
      battery_charge_light:
        friendly_name: "Battery Charge as Light"
        value_template: >
          {{ states('sensor.deye_sunsynk_sol_ark_battery_state_of_charge') | float > 0 }}
        level_template: >
          {% set charge = states('sensor.deye_sunsynk_sol_ark_battery_state_of_charge') | float %}
          {{ (charge * 2.55) | int if charge >= 0 else 0 }}
        turn_on: {}
        turn_off: {}
        set_level: {}

For some reason it did not, but thanks for your replies