Convert unit of measurement from kW to W

Hi, I have added a P1 WIFI gateway to Home Assistant. The code in configuration.yaml looks like this:

################################################################
#                                            P1 WIFI Gateway                                                    #
################################################################

  - platform: dsmr
    host: 192.168.3.9
    port: 8088
    dsmr_version: 5

  - platform: filter
    name: "Stroom verbruik"
    entity_id: sensor.power_consumption
    filters:
      - filter: time_throttle
        window_size: 00:01
      - multiply: 1000

  - platform: filter
    name: "Stroom levering"
    entity_id: sensor.power_production
    filters:
      - filter: time_throttle
        window_size: 00:01

recorder:
  exclude:
    entities:
      - sensor.power_consumption
      - sensor.power_production

The result in Lovelace is looking like this:

However I would like to display the power in Watts instead of kW. So the calculated results needs to be multiplied with 1000. I have tried to add this in configuration.yaml in several ways. However I didn’t found the right solution to do this. Who can help me? Thanks in advance for your support.

  - platform: template
      sensors:
        power_consumption_w:
          friendly_name: 'xxxxx'
          unit_of_measurement: 'W'  
          value_template: "{{(states('sensor.power_consumption') | float * 1000) | round(2)}}"
1 Like

Hi, Thanks for your reaction. I have added this code to my configuration.yaml file. It is working correctly and the power usage is displayed in Watt instead of kW. However, the new entity is updated every second instead of every minute (as configured in the “platform: filter” section). Is it possible to use your code together with the “platform: filter” functionality so that the measurements per minute are displayed in Watts?

Try to add: scan_interval: 60

1 Like

Unfortunately it doesn’t work. Do you have another solution? Thanks.

Did you try putting time_throttle window size in quotes, i.e. “00:01”?

1 Like

I have checked the time_throttle windows size. Quotes were not used, however values were refreshed correctly every minute. I have added a template platform to convert the sensor values from kW to W and to remove the decimals.

Please let me know if there is another solution available. Thanks in advance for your support.

The result looks like this:

The code in configuration.yaml looks like this:

  - platform: dsmr
    host: 192.168.3.9
    port: 8088
    dsmr_version: 5

  - platform: filter
    name: "stroom_verbruik_filter"
    entity_id: sensor.power_consumption
    filters:
      - filter: time_throttle
        window_size: 00:01

  - platform: filter
    name: "stroom_levering_filter"
    entity_id: sensor.power_production
    filters:
      - filter: time_throttle
        window_size: 00:01

  - platform: template
    sensors:
      stroom_verbruik:
        unit_of_measurement: 'W'  
        value_template: "{{(states('sensor.stroom_verbruik_filter') | float * 1000) | round(0)}}"
      stroom_levering:
        unit_of_measurement: 'W'  
        value_template: "{{(states('sensor.stroom_levering_filter') | float * 1000) | round(0)}}"

recorder:
  exclude:
    entities:
      - sensor.power_consumption
      - sensor.power_production
      - sensor.stroom_verbruik_filter
      - sensor.stroom_levering_filter
1 Like

I’m missing what the issue is now. Previously, you said the issue was that it was refreshing every second, not every minute. You now say it works.

The setup above works correctly. However I need two platforms. First platform filters the sensor values to one measurement per minute. The second platform converts the sensor value from kW to W. My question is if there is a possibility to do this easier.

1 Like