Template sensor error

Hi.
I am getting an error in my log when I have to restart home assistant manually after a crash etc. saying:

Template sensor ‘nodon_smart_plug_weekly_total’ has no entity ids configured to track nor were we able to extract the entities to track from the value template(s). This entity will only be able to be updated manually.

The sensor is used to track weekly power consumption for the zwave smart plug defined as such in my config.:

  # Sensor to read weekly power consumption of smart plug
  - platform: template
    sensors:
      nodon_smart_plug_weekly_total:
        friendly_name: "Nodon Smart Plug Weekly Total"
        unit_of_measurement: kWh
        value_template: "{{ states() | float | round(2) }}"

I have an automation which runs a python script once a week to calculate this total (from the cumulative total which is stored in the smart plug).
When up and running, the setup works fine and the total is updated is each week. It is only upon a system restart it fails.

I am still fairly new to scripting and expect it is something fairly simple, but any help greatly appreciated.

It’s because there’s nothing in states(). If you mean to just republish nodon_smart_plug_weekly_total then just put ‘sensor.nodon_smart_plug_weekly_total’ between the parens to eliminate the error.

Hi micque.
Thanks for the reply.
When you say ‘republish’, do you mean to refresh/update it?

Yes, whenever the value_template is reevaluated you are updating the state. If you put the sensor name in the states call it will take the current value, float, round and repost it.
You should consider using an input_number to store the value instead of a template sensor. Input_numbers have a built-in mechanism for updating and based on your code there isn’t anything else happening in your sensor code.

Great! Many thanks for the help :grinning:

1 Like