#Template integral sensor displays incorrectly on Energy dashboard

1 messages Β· Page 1 of 1 (latest)

obsidian patrol
#

Hi All,

So I am all into the Home-Assistant now, it is awesome!

However, I am running into an issue which I cannot seem to figure out;

Situation; I have 3D printers connected to 2 smart sockets that individually track the energy consumption. I want to add these together and display them as 1 entity on the energy dashboard.

What I did to try and achieve it;

  • I made a Template sensor helper that adds the 2 energy consumption together., which works if I check the values. (Image 1)

However, 2 things go wrong;

  • The combined sensor value occasionally drops to (or near) zero. Looking at the history graphs for the individual smart plugs, these drops do not exist thereβ€”only in the combined template sensor. When the sensor drops to 0 and then jumps back to its actual value (e.g., 1.34 kWh), the dashboard seems to interpret that jump as a massive surge of consumption. Currently, my dashboard shows 10 kWh used when the actual total is only 1.34 kWh. (Image 2 and 3)
  • The second issue is that the energy consumption values from the smart plugs reset every week. However, I would like my combined template sensor to be a "total increasing" sensor that keeps climbing regardless of the weekly resets of the child sensors.

My questions;

  • How can I prevent the template sensor from dropping to 0 randomly? (I have a feeling it has something to do with a disruption in connection)
  • Is there a better way to ensure the combined total doesn't reset when the plugs do?
dusk kelp
#

The issue you have is probably that the sensors are going unavailable/unknown which evaluates to 0 in a template but doesn't show up in the graph
You can solve this with a trigger template and not_to unknown/unavailable which will stop the template sensor updating if they're wrong, or you can do it in the normal template editor but it's more fiddly

#

To stop it resetting, I think you can use a utility meter helper

worn token
#

Don't make template sensors with total increasing with just a float-filter with a default of 0. Add a propper availability. As you posted everything as picture rather then code I'm not going t make it, but I usually use the is_number-filter.

But even then, it is still tricky. As if one of the two plugs resets, HA seen that also as a reset of the template sensor. But the template sensor does not reset to 0 but to the value of the other plug. Which HA then sees as consumption. If you're sure the plugs never reset (or can life with manually changing the statistics when it happens), it's fine. Otherwise a solution would be to pass the plugs energy sensors through a utility meter as that will then not reset when the plug does. And use the utility meter sensor in the template sensor sum. But still, I would recommend a propper availability.

obsidian patrol
#

as for the utility meter, makes sense, how should I proceed to do that? just add the combined input into a utility meter helper??

worn token
#

State can be:

  states('sensor.smart_plug_3_totaal_energieverbruik') |float 
  + states('sensor.smart_plug_4_totaal_energieverbruik') |float 
}}```

And add availability
```{{
  states('sensor.smart_plug_3_totaal_energieverbruik') |is_number 
  and states('sensor.smart_plug_4_totaal_energieverbruik') |is_number 
}}```
#

As for the utility meter, no, the other way around. Make a utility meter per plug (without cycle). And change the tempalte sensor to use the utility meters

dusk kelp
#

this is what a full triggered sensor should look like:

  - trigger:
      - trigger: state
        entity_id: sensor.3D_printer_A_energy
        not_to:
          - unknown
          - unavailable
          - "0"
        not_from: 
          - unknown
          - unavailable
      - trigger: state
        entity_id: sensor.3D_printer_B_energy
        not_to:
          - unknown
          - unavailable
          - "0"
        not_from: 
          - unknown
          - unavailable
    sensor:
      - name: 3D Printer A+B Energy Sum
        unique_id: <insert something>
        state: '{{ this.state | float + [(trigger.to_state.state | float - trigger.from_state.state | float), 0] | max}}'
        device_class: energy_storage
        state_class: measurement
        icon: mdi:power-plug
        unit_of_measurement: 'kWh'

It should ignore any of them resetting out of sync, going unavailable, or otherwise decreasing because of some error - doesn't need a utility meter either, but requires you to set it up in yaml config, @worn token's answer is maintainable from the UI

obsidian patrol
worn token
#

@dusk kelp Yeah, that should also work. Although set a default of 0 on the state to make it work from the start (aka, from unknown)

dusk kelp
#

yes, though would probably go with the utility meter + availability solution if you're newer to it cos I'm sure there's some edge case I've missed

#

as @worn token kindly pointed out πŸ˜›

obsidian patrol
#

ahahah

#

ohkeee

#

Is this how I should set up the Utility meter??

dusk kelp
#

yes, looks right

obsidian patrol
#

Cool, so I have made 2 meters

obsidian patrol
#

Should I use

  states('sensor.3d_printers_verbruiksmeter') |float 
  + states('sensor.prusa_xl_verbruiksmeter') |float 
}}```

Or 
```{{
  states('sensor.3d_printers_verbruiksmeter') |is_number 
  and states('sensor.sensor.prusa_xl_verbruiksmeter') |is_number 
}}```
worn token
#

Both, first is for the state, second is voor de availability (weirdly hidden under Advanced options)

#

And don't forget to change the entity id's in both to the newly created utility meters

obsidian patrol
#

yeahh these are the utility meters πŸ™‚

#

ohkee, and which type of sensor helper should I make??

worn token
#

Ah, okay, plug has multiple printers? πŸ˜„

obsidian patrol
#

I have 5 3D printers in 2 wall sockets πŸ™‚

#

oopss

worn token
#

πŸ˜„

obsidian patrol
#

but should I make a combine sensor??

#

or energy template sensor??

worn token
#

You should still make a template sensor. With device class energy, state class total increasing and unit the same as the sources.

obsidian patrol
#

So like this?

worn token
#

Looks good, although I can't verify the unit of measurement of course. You would not be the first to have the source as Wh and make a template in kWh without transforming πŸ˜„

#

Then you're a factor 1000 off

obsidian patrol
#

Fair

#

it still shows unavailable but that might be because the sockets did not yet update, right??

worn token
#

(and man, I didn't know there is so much translation missing in Dutch... I use English for all but man, that windows is a real mix.)

worn token
obsidian patrol
#

hmm it still says unkown for the utilitity meters, which is wierd because the derivative sensors update every 5minutes

worn token
#

The Utility meter you show isn't unknown so that one works. And the other one?

And what do you mean by "derivative sensors" ?

obsidian patrol
#

Sorry I understand it is a bit vague.

I now see both Uitility meters updating, although with a very long update intervall. Is that normal??

#

as for the combined, it still does say unknown

#

So the utility meters work;

#

But the template sensor that should combine the 2 does not...

#

Which we made like this;

#

I tried to make a sum helper that just combines the 2 utility meter readouts, but this then is not selectable in the energy dashboard

worn token
#

For the utility meters, they should just follow the same pattern and updates as the source. But as the scale for the utility meters is still pretty small, as they start at 0, I think the steps now just stand out more.

#

For the template sensor, do a check on the entity id. Unless you renamed them I would expect 'sensor.verbruiksmeter_3d_printers' and not 'sensor.3d_printers_verbruiksmeter'. So I think the entity id's are not correct.

obsidian patrol
#

it autofills them, and finds the value

worn token
#

If you switch to dev tools (Settings => Dev tools => Template), things should be easier to debug. Can you just do there:

{{ states('sensor.3d_printers_verbruiksmeter') |float }}
{{ states('sensor.prusa_xl_verbruiksmeter') |float }}
{{ states('sensor.3d_printers_verbruiksmeter') |is_number }}
{{ states('sensor.prusa_xl_verbruiksmeter') |is_number }}
{{
  states('sensor.3d_printers_verbruiksmeter') |float
  + states('sensor.prusa_xl_verbruiksmeter') |float
}}
{{
  states('sensor.3d_printers_verbruiksmeter') |is_number
  and states('sensor.prusa_xl_verbruiksmeter') |is_number
}}

What is the output?

worn token
#

In the availability you have for the seconde entity sensor.sensor.bla

#

that's one sensor to many πŸ˜„

obsidian patrol
#

tbh I dont fully know what the availability section does

#

Ohhhhh wait!

#

I see it

#

this is now good?

worn token
obsidian patrol
#

hehehe nice!

#

ohkee thanks!

#

another quick question then, I have a few other energy sensors, how do I add them to a custom enenergy dashboard, so they show the same period? (sync with the date selection bar)

worn token
#

If the template in the availability section renders true (in this case, both entities contain a number), it will render the state as given by the state template.

But if the availability template renders true (aka, one or both entities don't contain a number, most likely because they are unavailable) then the template sensor render 'unavailable'. This has special status in HA and tells things like the energy dashboard there just is not data. And it will just ignore things until it has valid data again.

#

mm, so you don't want them to be included in the normal energy dashboard? That's going to be a bit hard. Maybe there is a custom component available for it....

obsidian patrol
#

I have a sensor of the battery which I want to add in a custom dashboard, and only display the data for the respecitve set period

worn token
#

I see the custom Sankey card has support to listen to the date selecter via energy_date_selection

obsidian patrol
#

Which Sankey??

I only have the flow graph that it shows

worn token
obsidian patrol
#

But this only makes the flow charts, right??

#

I just have a sensor that tracks the money saved, and I want to sync it with the date selection thingi