Convert kW tot Watt

Do I need to place that piece of code in the editor like this?

Sorry for my possibly stupid questions. I am just a real newbie

Nope. That’s not where you put it.

Put it in your configuration.yaml file. You should see a line that says sensor:

Put it all under it like this:

sensor:
  - platform: template
    sensors:
      dsmr_in_watts:
        friendly_name: "Current Power Usage"
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.dsmr_reading_electricity_currently_delivered')|float * 1000 }}"

Unless your sensor line looks like this (which I think it does by default):

sensor: !include sensors.yaml

Then you actually have to put the template sensor in your sensors.yaml file - without the first line (sensors:) like this:

- platform: template
  sensors:
    dsmr_in_watts:
      friendly_name: "Current Power Usage"
      unit_of_measurement: "W"
      value_template: "{{ states('sensor.dsmr_reading_electricity_currently_delivered')|float * 1000 }}"

After saving the sensors.yaml file restarting home assistant this will create a sensor called sensor.dsmr_in_watts that you can use in your gauge card.

1 Like

You don’t need anymore to restart Home Assistant to update Templates by the way, you just have to restart Template category and that’s so sweet ! :slight_smile:

I’ve had bad experiences reloading only parts of HA. I tend not to do it unless I’m in a real hurry (my server restarts in under a minute).

Thanx, perfect solution. I need that to.

Thanks a lot. Was looking for this.

Since a few releases HA has changed the Consumption from W to KW.
Unless you are a high consumer you will see 0 KW used or 1.

I knwo that you can now change it by pressing the entity and then the wheel.
Change KW to W and the precision. Otherewise I only 0 W used.

Pretty anoying because you have to do this everytime you reboot. Yes can use a template to achieve it but it lacks sometimes by a min so not accurate. Also it does not give the Graph.

@tom_l Any ways to make it persistent between reboots? or HA can simply revert it back so how it was?

I’m not sure what you are talking about. Regarding the unit change. Which integration do you use to create these sensors?

Template sensors update as soon as their source sensors update. And to be used in graphs all you have to do is add a unit_of_measurement.

1 Like

Integration is DSMR Slimme Meter.
The sensor is called sensor.electricity_meter_power_consumption

Are you saying I should use not this one but the other one called DSMR Reader?

I am using the integration and have the same Kw / W issue. (So after reboot my read out says Kw again instead of W. And after every reboot i have to put it back).

1 Like

There is an issue open for this:

Do not add “me too” comments. Just :+1: the first post to indicate you have the same issue.

1 Like

Done it :slight_smile:

Also did the thumbs up

I tried to copy your suggestions and put this in the configuration.yaml:

Adding two values worked, but multiplying didn’t.

template:

  • sensor:
    • name: “total_grid-eskom”
      unit_of_measurement: “A”
      device_class: power
      state: >
      {{ [ states(‘sensor.meter_grid_main_strom_der_phase_a’),
      states(‘sensor.meter_grid_battery_strom_der_phase_a’) ]
      | map(‘float’,default=0) | sum }}
      availability: >
      {{ not ‘unavailable’ in
      [ states(‘sensor.meter_grid_main_strom_der_phase_a’),
      states(‘sensor.meter_grid_battery_strom_der_phase_a’) ] }}

sensor:

  • platform: template
    sensors:
    meter_grid-main-w:
    friendly_name: “Current Power Usage”
    unit_of_measurement: “W”
    value_template: “{{ states(‘sensor.meter_grid_main_phase_a_leistung’)|float * 1000 }}”

I am novice but tempted by the possibilities of Home Assistant. Where is my error?

I cant tell because you have not formatted your post correctly.


template:
  - sensor:
    - name: "total_grid-eskom"
      unit_of_measurement: "A"
      device_class: power
      state: >
        {{ [ states('sensor.meter_grid_main_strom_der_phase_a'), 
            states('sensor.meter_grid_battery_strom_der_phase_a') ]
            | map('float',default=0) | sum }}
      availability: >
        {{ not 'unavailable' in 
            [ states('sensor.meter_grid_main_strom_der_phase_a'), 
              states('sensor.meter_grid_battery_strom_der_phase_a') ] }}


sensor:
  - platform: template
    sensors:
      meter_grid-main-w:
        friendly_name: "Current Power Usage"
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.meter_grid_main_phase_a_leistung')|float * 1000 }}"

Try this:

template:
  - sensor:
      - name: "total_grid-eskom"
        unit_of_measurement: "A"
        device_class: current
        state: >
          {{ [ states('sensor.meter_grid_main_strom_der_phase_a'), 
              states('sensor.meter_grid_battery_strom_der_phase_a') ]
              | map('float',default=0) | sum }}
        availability: >
          {{ has_value('sensor.meter_grid_main_strom_der_phase_a') and
             has_value('sensor.meter_grid_battery_strom_der_phase_a') }}

      - name: "Current Power Usage"
        unit_of_measurement: "W"
        device_class: power
        state: "{{ states('sensor.meter_grid_main_phase_a_leistung')|float(0) * 1000 }}"
        availability: "{{ has_value('sensor.meter_grid_main_phase_a_leistung') }}"

THANKS!! You did it.

1 Like

Can I also substract? Just exchanging the “+” by “-” didnt work.
Can these operations done with more than two Values?

      - name: "Meter Grid H1 in Watt"
        unit_of_measurement: "W"
        device_class: power
        state: "{{ states('sensor.meter_grid_main_watt')|float(0) - states('sensor.meter_grid_cottage_watt')|float(0) }}"
        availability: "{{ has_value('sensor.meter_grid_main_watt') }}"

Is there a reference overview for these operations, which you would recommend?

I agree with Tom. My Home Assistant restarts in about 30-seconds, which is how long it would take for me to find the "Template Category:.