Altering the gauge component with yaml file?

So I was following the second part of this tutorial he uses a custom yaml file to alter the gauge and change the lbs from the scale to a percentage based on a formula. Starts about 6 min in. I added a custom template within the config.yaml file like so…

# Loads default set of integrations. Do not remove.
default_config:

customize: !include keg-management-system.yaml

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

My custom yaml file looks like this…

template:
- sensor:
- name: "Keg 1 Level"
unique_id: 'kgl1'
unit_of_measurement: "%"
state: "{{ ((states('sensor.keg_scale_one_hx711_value')|float - states('input_number.keg_1_empty')|float ) / ((states('input_number.keg_1_full')|float - states('input_number.keg_1_empty')|float) / 100)) | round | int }}"

It doesn’t seem to be working though. Both the scale weight in lbs and the gauge are still reading the same thing…

https://www.home-assistant.io/integrations/homeassistant/#manual-customization

homeassitant:
  customize: !include keg-management-system.yaml

Are you sure you are customizing an existing sensor?

The YAML code you have copied (although not correctly formatted) looks to me like you are trying to create a new template sensor based on the existing one.

1 Like

Shit. I missed that. Yeah that is not a customise include.

I believe that’s what he does in the video. I’ve created two helpers keg_1_empty and keg_1_full. It’s supposed to use those two numbers to calculate the percentage of beer left in the keg and change the gauge.

Not sure if I’m doing it right though. His code uses a unique_id but I’m not sure if that is supposed to target that gauge component instance.

He puts all his code directly into the config.yaml file but I thought it might be safer to include the code instead. The code seems to validate fine but I don’t think it’s being implemented.

I skipped through the video but nowhere in that did he say to use customize. Watch it again. Closely.

He didn’t I know. He put his code directly in the config.yaml file I was running into errors when I tried it the first time though.

So why did you put a template sensor in customize?

You can’t just make shit up.

And your template sensor is not indeted correctly.

configuration.yaml:

template: !include templates.yaml

templates.yaml:

- sensor:
    - name: "Keg 1 Level"
      unique_id: 'kgl1'
      unit_of_measurement: "%"
      state: "{{ ((states('sensor.keg_scale_one_hx711_value')|float - states('input_number.keg_1_empty')|float ) / ((states('input_number.keg_1_full')|float - states('input_number.keg_1_empty')|float) / 100)) | round | int }}"

Apologies I’m a total noob with Home Assistant and coding in yaml. I’m a web developer so I know my way around a lot of coding languages but this is my first time coding in yaml. :stuck_out_tongue:

Does it matter what order I place that include in the config file?

No it doesn’t.

Thanks for all your help. I updated my config file and template file. Still looks like it’s not calculating the percentage correctly though. The % is still the same weight as lbs.


Oh wait I think I figured it out! I see the template as an entity now and can change the gauge to us it! Thanks and thank you for your patience!