Virtualpowermeter

Hello !
Is it possible to realize a virtualpowermeter?
So I assign a value to a lamp z.b 8 watt and a counter on the basis of the states on / off the consumption calculated.

Would like to know this also!

Iā€™m doing something like this for my lights with template sensors

Assuming a lamp consumes an average of 9.5 watts, the current power consumption in watts (ā€œWā€) can be calculated with a template sensor in the sensors.yaml as follows:

  - platform: template
    sensors:     
      stromverbrauch_light_deckenlampe_bad:
         unit_of_measurement: "W"
         entity_id: light.deckenlampe_bad
         value_template: >-
           {% if is_state('light.deckenlampe_bad', 'on') %}
             9.5
           {% else %}
             0
           {% endif %}

And for the power consumption over time in kWh you can combine a template sensor it with an history sensor an calculate it as follows:

  - platform: history_stats
    name: Deckenlampe Bad AN Jahr
    entity_id: light.deckenlampe_bad
    state: 'on'
    type: time
    start: '{{ now().replace(month=1).replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

  - platform: template
    sensors:    
      gesamtverbrauch_light_deckenlampe_bad:
        value_template: '{{ states.sensor.deckenlampe_bad_an_jahr.state | multiply(0.0095) | round(2)}}'
        unit_of_measurement: 'kWh'
        friendly_name: 'Gesamtverbrauch Deckenlampe Bad'

A quick hint. My history sensor (history_stats) used here, which measures how long a certain light was on during this year, automatically resets at a new beginning of the year.
So I only measure the annual consumption for the current year in Homeassistant. If you want this to be different, you have to adjust the history_stats sensor accordingly.

Hope that helps you a little?

yes fine, next step calculate price day, month :slight_smile:

I think you can accomplish this already by using a switch or light entity, a template sensor and a utility meter?

Untested:

sensor:
  platform: template
  sensors:
    mylight_power:
      value: >-
          {% if is_state('light.mylight', 'on') %}
            8
          {% else %}
           0
          {% endif %}
      unit_of_measurement: W

utility_meter:
  etc.
1 Like