Rounding issue with utility meter

Hi there!

New HA user here and loving all the tinkering so far. I’m running into an odd issue where I can use your help. I have spend an hour googling my butt off and looking at as many forum topics as I could but I don’t seem to be able to find the answer. I’m really hoping somebody else can help me out!

What I’m trying to achieve
I would like to track my energy consumption over time using the utility meter integration and the Plugwise P1 meter.

What has happened so far
I managed to create my utility meter (using wonderful tutorials on YT btw, awesome this community!) and the numbers seem to be correct. However, both my Lovelace card as well as the sensor state has like a zillion decimals. Now, I like data, but I don’t need this much :wink: Because a picture speaks a thousand words, this is happening:

The P1 integration does not seem to provide all these decimals AFAIK. So I have no clue where these decimals are coming from.

Here’s my config in case that’s relevant:

# Build energy meter with Plugwise P1
  hourly_energy:
    source: sensor.p1_net_electricity_cumulative
    cycle: hourly
    tariffs:
      - peak
      - offpeak        
  daily_energy:
    source: sensor.p1_net_electricity_cumulative
    cycle: daily
    tariffs:
      - peak
      - offpeak    
  weekly_energy:
    source: sensor.p1_net_electricity_cumulative
    cycle: weekly
    tariffs:
      - peak
      - offpeak  
  monthly_energy:
    source: sensor.p1_net_electricity_cumulative
    cycle: monthly
    tariffs:
      - peak
      - offpeak  
  quarterly_energy:
    source: sensor.p1_net_electricity_cumulative
    cycle: quarterly
    tariffs:
      - peak
      - offpeak  
  yearly_energy:
    source: sensor.p1_net_electricity_cumulative
    cycle: yearly
    tariffs:
      - peak
      - offpeak

What I would like
A utility meter with just two decimals :slight_smile:

Can somebody point me into the right direction? If I do need to start creation additional sensors based on templates (which would be an overhead IMHO), could then somebody help meby sharing an example? Really appreciate your time and help!

1 Like

I have been playing around with the above since posting. There seem to be various users figuring out how to round sensor data which has even resulted into feature requests.

From what I know now, as a user you are not able to change the rounding on sensors from either the UI or, in my case, the Plugwise P1 integration (please anybody - correct me if I’m wrong). So I have decided to create a new set of rounded sensors by using the templating feature. I have figured out how to do that by Googling and playing around. Posting here for any future users who run into similar issues:

sensor:
  - platform: template
    sensors:
    # Plugwise and/or HA give too many decimals. Let's round these for useability. First peak energy sensors:  
      hourly_energy_peak_rounded:
        friendly_name: "Uurlijks peak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.hourly_energy_peak') | float | round(2) }}"  
      daily_energy_peak_rounded:
        friendly_name: "Dagelijks peak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.daily_energy_peak') | float | round(2) }}"
      weekly_energy_peak_rounded:
        friendly_name: "Wekelijks peak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.weekly_energy_peak') | float | round(2) }}"  
      monthly_energy_peak_rounded:
        friendly_name: "Maandelijks peak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.monthly_energy_peak') | float | round(2) }}"
      yearly_energy_peak_rounded:
        friendly_name: "Jaarlijks peak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.yearly_energy_peak') | float | round(2) }}"
    # And then round offpeak energy sensor 
      hourly_energy_offpeak_rounded:
        friendly_name: "Uurlijks offpeak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.hourly_energy_offpeak') | float | round(2) }}"  
      daily_energy_offpeak_rounded:
        friendly_name: "Dagelijks offpeak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.daily_energy_offpeak') | float | round(2) }}"
      weekly_energy_offpeak_rounded:
        friendly_name: "Wekelijks offpeak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.weekly_energy_offpeak') | float | round(2) }}"  
      monthly_energy_offpeak_rounded:
        friendly_name: "Maandelijks offpeak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.monthly_energy_offpeak') | float | round(2) }}"
      yearly_energy_offpeak_rounded:
        friendly_name: "Jaarlijks offpeak energieverbruik"
        unit_of_measurement: 'kWh'
        value_template: "{{ states('sensor.yearly_energy_offpeak') | float | round(2) }}"         
4 Likes

That is a solution for sure, let’s see if the feature request gets implemented though - it would be more elegant :wink:

2 Likes

An alternative solution here:

I’ve just implemented this due to having the same issue and found it worked well without having to create additional sensors.

I know this is an old thread but i found this solution hard to find and this thread kept coming up when searching for solutions. So thought others would probably be in a similar situation.

1 Like

As alternative use javascript:

label: "[[[ return Math.round(Number(states[<<YOUR SENSOR>>].state)).toFixed(0); ]]]"
1 Like

I got same issue. I have created utility meter which show so many decimals.

Solution is very simple - open your utility meter from Helpers - hit Settings - Display precision.

1 Like