Issues with my template sensors. Please help

Hi all. new to this. have been going back and forth from search’s trying to fix this so sorry if it has been covered before.

I have 2 template sensors I am trying to get working. the first is a subtraction between 2 sensors.

self_consumption:
        value_template: '{{ (states.sensor.energy_generation | float ) -  (states.sensor.grid_sold_energy_day | float)}}'
        friendly_name: "self_consumption"
        unit_of_measurement: "kWh"

and the problem is it returns 0 and in the template tool I get “This template does not listen for any events and will not update automatically.” This is probably easy but I am a little fried from trying to work it out.

the second is a multiplication of a sensor and a value.

      dryer_consumed_kW:
        value_template: "{{ states('sensor.dryer_electric_consumed_w') | float * 0.001 }}"
        friendly_name: "dryer_consumed_kW"
        unit_of_measurement: "kW"

this seems to be ok in the template builder but when doing a configuration check I get a big error.

Invalid config for [sensor.template]: invalid slug dryer_consumed_kW (try dryer_consumed_kw) for dictionary value @ data[‘sensors’]. Got OrderedDict([(‘power_consumption’, OrderedDict([(‘value_template’, “{% if is_state_attr(‘sensor.pvoutput’, ‘power_consumption’, ‘NaN’) %}0{% else %}{{ state_attr(‘sensor.pvoutput’, ‘power_consumption’) }}{% endif %}”), (‘friendly_name’, ‘Using’), (‘unit_of_measurement’, ‘Watt’)])), (‘energy_consumption’, OrderedDict([(‘value_template’, ‘{{ “%0.1f”|format(state_attr(“sensor.pvoutput”, “energy_consumption”)|float/1000) }}’), (‘friendly_name’, ‘Used’), (‘unit_of_measurement’, ‘kWh’)])), ('power_… (See ?, line ?).

Anyway hope you guys can point me in the right direction.

First one, you are not accessing the entity states correctly, should be:

      self_consumption:
        value_template: "{{ states('sensor.energy_generation') | float  -  states('sensor.grid_sold_energy_day') | float)}}"
        friendly_name: "Self Consumption"
        unit_of_measurement: "kWh"

See here for more info: https://www.home-assistant.io/docs/configuration/templating/#states pay particular attention to the warning.

Second one you got the state correctly but dont use capital letters for the slug (as it says in the error):

      dryer_consumed_kw: # lower case only, no spaces or special characters other than _
        value_template: "{{ states('sensor.dryer_electric_consumed_w') | float * 0.001 }}"
        friendly_name: "Dryer Consumed kW" # can contain any character
        unit_of_measurement: "kW"
1 Like

Thank you. I know it would be something simple. I see what i did wrong in the first one but not the second one. Will have a good look tonight when I get all the kids to bed.

Once again thank you.

Yours:

dryer_consumed_kW:
                ^--- capital letter

Mine:

dryer_consumed_kw:
                ^--- lower case

Thanks for that.

5 posts were split to a new topic: Template issues now