Rounding input for gauge card ... template?

Ok, I’m just not making progress. I’m a noob to HA and I’m totally confused. I’ve installed the HA OS version and am getting data from my Fronius inverter etc. and I have installed HACS and explored the treasure trove of extensions and addons. As long as I stay within the UI configuration system then all is sweet. However I cannot fathom how to connect to the scripting system. The documentation doesn’t seem to align with the new UI in most cases and almost none of the vids etc on google still seem relevant.

As a simple example I have added the HA standard Gauge card to a new dashboard and it displays the power from my solar panels using an entity supplied by the inverter API: sensor.solarnet_power_photovoltaics.

However the value displays with a large number of decimals which I wish to round off. I have identified using a template as a solution, but the Gauge card doesn’t seem to accept a template in the entity field. I assume therefore that I must create an intermediary entity to perform the rounding, and then to point the Gauge card to that?

I have tried entering script code in the configuration.yaml file but it doesn’t seem visible to the UI, or else just generates errors. So far I have crashed on every attempt.

I will be ever so grateful if some kindly soul will clearly spell out for me:

  1. The way to write a suitable template script to do the rounding
  2. The way to write (or load) an intermediary entity, if that is the correct approach
  3. Which file(s) these scripts should reside in, to link to a UI generated gauge in the frontend
  4. Anything else that would help me. eg. Is there a UI card that could be used as the intermediary?

I expect the template script might look something like this, but have no idea how to tie it into the system:

  - type: gauge
    entity: sensor.solarnet_power_photovoltaics
    name: Solar Power Production
    template: "{{ (sensor.solarnet_power_photovoltaics | round(1)) }} W"

NB. I’m happy to use a HACS card or entity, such as gauge-card if that is easier.

I hope that if I have even one example of the steps to follow I can make progress on my other problems. Thanks so much, in advance. Cheers, Stephen.

Try:

    template: "{{ states(sensor.solarnet_power_photovoltaics) | round(1) }} W"

Also the template editor in Developer Tools is handy for troubleshooting these things.

EDIT: also I don’t know that you can supply the entity as a template. Create a template sensor then use that sensor in the gauge card.

In case you have trouble finding it in the docs, add a template sensor to configuration.yaml:

template:
    sensor:
      - name: "Adjusted Power"
        state:  "{{ states(sensor.solarnet_power_photovoltaics) | round(1) }}"
        unit_of_measurement: "W"

Cool, thanks Darryl. Thanks so much for your lightning reply! :+1:

That is the nub of my problem, I think. I’ve tried so many times to connect between configuration.yaml and the frontend UI, but I haven’t been able to yet. Thanks for the template and links … I’ll give it a go. Cheers, Stephen

Some changes to configuration.yaml require you to restart - they have made it much better lately but if you are having issues a config check followed by restart is recommended.

Ok, thanks. Cheers.

I played around a bit with card templater (hacs) and got it to work
example with an input helper that shows 5.0
normal:
image

templater
image

code:

type: custom:card-templater
card:
  type: gauge
  entity: input_number.sunsetmin
entities:
  - entity: input_number.sunsetmin
    state_template: '{{ states("input_number.sunsetmin") | int(0) }}'
2 Likes

Hey, thanks @vingerha. The card-templater looks very promising. I’ve been trying to follow your example, but the magic has not revealed itself yet.

However, it’s past 11pm here in New Zealand now and I’ve got work first thing in the morning, so I’m going to have to go crash. Plenty to try tomorrow night!

Thanks to you both - really appreciated. :+1:

Cheers, Stephen