Current power use how calculate

Hello all,

I want to create a Gauge Card to see how much power I currently use.
To get data, I need to calculate the following:
Power production (Solar panels) - Power return to grid (P1 monitor) + Grid use = Current Power use

I’m new in Home assistant, hop somebody can help with it ?

sensor:
  - platform: template
    sensors:
        power_total:
            friendly_name: "Power total"
            unit_of_measurement: 'W'
            value_template: '{{ (states("sensor.griduse") | float + states("sensor.solarproduction") | float - states("sensor.gridreturn") | float) | round }}'

Change sensor names to yours and place this in configuration.yaml
Restart HA

You can make gauge with the new sensor.power_total

Hello BabeMischa,

Thank you for your reply, I have added it to configuration.yaml and tray to restart HA but i get error

Failed to restart Home Assistant

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected char '“' at 11) for dictionary value @ data['sensors']['power_total']['value_template']. Got '{{ (states(“sensor.phases_power_consumed_phase_l1") | float + states("sensor.solaredge_ac_power”) | float - states("sensor.smartmeter_power_production”) | float) | round }}'. (See ?, line ?).

I have added your script in “/config/configuration.yaml” as follows and change Entity’s to mine.

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  auth_mfa_modules:
    - type: totp
    
sensor:
  - platform: template
    sensors:
        power_total:
            friendly_name: "Power total"
            unit_of_measurement: 'W'
            value_template: '{{ (states(“sensor.phases_power_consumed_phase_l1") | float + states("sensor.solaredge_ac_power”) | float - states("sensor.smartmeter_power_production”) | float) | round }}'

I don’t know, how you did it, but the two symbols look different. That’s, what the system thinks too :slight_smile:

afbeelding

you have that on more places. :wink:

The one on the right side is the good one.

1 Like

Thank you for your great support :slight_smile: , it works.

I have created wrong symbols because I use Mac, look like you get different symbols.

1 Like

There are a few issues with that solution.

You should use the new format for template sensors.

You should define defaults for your filters.

You should use an availability template to prevent erroneous readings when one or more sensors are unavailable.

e.g. (configuration.yaml)

template:
  - sensor:
      - name: "Power total"
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement 
        state: > 
          {{ (states('sensor.phases_power_consumed_phase_l1') | float(0) +
              states('sensor.solaredge_ac_power') | float(0) - 
              states('sensor.smartmeter_power_production') | float(0)) | round(0) }}
        availability: >
          {{ states('sensor.phases_power_consumed_phase_l1') | is_number and 
             states('sensor.solaredge_ac_power') | is_number and 
             states("'sensor.smartmeter_power_production') | is_number }}

Nice, i see, i can learn more… :wink:

1 Like

Hi there,
my sensor for PV power stops being available after the inverter shuts down when it gets dark. Is there a way to assume zero watts when the PV sensor is not available?
How would I do that?

Thanks in advance!

I tried this but it does not seem to work…

template:
  - sensor:
      - name: "Power total"
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement 
        state: > 
          {{ (states('sensor.phases_power_consumed_phase_l1') | float(0) +
              (states('sensor.solaredge_ac_power') if states('sensor.solaredge_ac_power') | is_number else 0) | float(0) - 
              states('sensor.smartmeter_power_production') | float(0)) | round(0) }}
        availability: >
          {{ states('sensor.phases_power_consumed_phase_l1') | is_number and 
             states('sensor.smartmeter_power_production') | is_number }}