Virtual Meter Device with manipulate Value

Hi Everybody,
I am using to detect my power consumption of my PV an Sonoff device. Everything works fine, flashed tasmo.
but I have one issue, my Electric converter needs 8w if the PV doesn’t produce Power.
So i have in my Metering at night 8w which will detect as production, how can I Create an device which will have the same prop of the sensor but remove 8w.
can someone help me?

I hope I wrote the Explanation correct and understandable…

greetings
Simon

template:
  - sensor:
      - name: "Corrected PV Power"
        unit_of_measurement: "W" # or kW
        state_class: measurement
        device_class: power
        state: "{{ states(sensor.your_pv_power_sensor_here')|float(0) - 8 }}"
        availability: "{{ states(sensor.your_pv_power_sensor_here')|is_number }}"
1 Like

I have following issue

Logger: homeassistant.config
Source: config.py:867
First occurred: 09:18:37 (1 occurrences)
Last logged: 09:18:37

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected char "'" at 44) for dictionary value @ data['sensor'][0]['state']. Got "{{ states(sensor.sensor.tasmota_energy_power')|float(0) - 8 }}". (See /config/configuration.yaml, line 60).
   sensor:
      - name: "Justiert"
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        state: "{{ states(sensor.sensor.tasmota_energy_power')|float(0) - 8 }}"

Oops. Missing a single quote. Should be:

state: "{{ states('sensor.sensor.tasmota_energy_power')|float(0) - 8 }}"
1 Like

no my fault, i have to check better what i copy paste, thanks for help tom.

Nah, it was missing in my posted config. Make sure you fix both templates.

how do you mean both templates?
currently it shows unknown, no formatting issues but the value will not calc,

Both the availability and state templates are missing the first ’ as I copied and pasted the state template into the availability template when I wrote it to save time.

i got 1 time an value -8w but thats it

Post your current template and any relevant errors in the log.

sensor:
  - name: "Justiert"
    unit_of_measurement: "W"
    state_class: measurement
    device_class: power
    state: "{{ states('sensor.sensor.tasmota_energy_power')|float(0) - 8 }}"
    availability: "{{ states('sensor.sensor.tasmota_energy_power')|is_number }}"

my implementation
the result is image

so i had now a little more time, just boring meetings, i find out in the dev template he cannot show the sate object.
I will spend time for more investigation, sorry for you, that i take your time

How is that included in your config?

Also your entity ids are confusing. Are they energy or power?

There’s no such thing as “energy_power”.

where can i see it? i just have the tasmota integration added

Ha. Oh dear. This only updates when the doorbird event occurs.

template:
  - trigger:
      - platform: event
        event_type: "doorbird_turstation_klingelt"
    binary_sensor:
      - name: doorbell_is_ringing
        state: on
        auto_off: "00:00:30"
        device_class: occupancy
      - name: lichtschalter_eingang
        state: "off"
        device_class: light
    sensor:
      - name: "Justiert"
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        state: "{{ states('sensor.sensor.tasmota_energy_power')|float(0) - 8 }}"
        availability: "{{ states('sensor.sensor.tasmota_energy_power')|is_number }}

Try pressing your doorbell - the energy sensor will update :slight_smile:

What you want is this:

template:
  - trigger:
      - platform: event
        event_type: "doorbird_turstation_klingelt"
    binary_sensor:
      - name: doorbell_is_ringing
        state: on
        auto_off: "00:00:30"
        device_class: occupancy
      - name: lichtschalter_eingang
        state: "off"
        device_class: light

  - sensor:
      - name: "Justiert"
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        state: "{{ states('sensor.sensor.tasmota_energy_power')|float(0) - 8 }}"
        availability: "{{ states('sensor.sensor.tasmota_energy_power')|is_number }}

I found the issue it is one ‘sensor’ to much

sensor:
      - name: "Justiert"
        unit_of_measurement: "W"
        state_class: measurement
        device_class: power
        state: "{{ states('sensor.tasmota_energy_power')|float(0) - 8 }}"
        availability: "{{ states('sensor.tasmota_energy_power')|is_number }}"

No. Look what I wrote.

You included the energy sensor in the triggered sensor. it needs to be a separate sensor (by using - in front of sensor:). The indention is also very important, and missing from your last pasted example above, so that is confusing.

haha :smiley: Thanks for the tipp

So @tom_l Thanks for Support yes now i changed it and it works, thanks for the perfect support.
so i will now try to avoid that the value will not under 0, hopefully it would be not a big work.

i learned now a lot about thanks tom :smiley:

1 Like

are there 2 ways to write an template sensor? @tom_l

template:
 -sensor:
   - name: sensorx

or

- sensor:
   - platform: template
   - name: sensorx

Yes there are. The new format which goes under the template: integration and the old ‘legacy’ template sensor platform which goes under the integration sensor: as -platform: template

While the old format will continue to be supported it is recommended that you use the new format for all new sensors as if new features are added they will likely not be added to the old legacy format.

1 Like