After upgrade to 2202.4.4 my template sensor wont work

i updated HA from 2202.3 to 2202.4.4. After the update is see the following error in the log:

Invalid config for [template]: [value_template] is an invalid option for [template]. Check: template->sensor->0->value_template. (See /config/configuration.yaml, line 17).

my template configuration looks like

  - sensor:
      - name: "garagentor_position_invertiert" # Erzeuge Invertierte Gargentor Position
        unit_of_measurement: '%'
        value_template: "{{ ( 100 - (states('sensor.garagentor_position') | int))  }}"

What have changed and how can i fixed it? I need this template to invert my garage door sensor.

That template would have never worked as value_template is not a valid field in the new template style. This error would be produced day one when you added this template into your system. You’re mixing the legacy template sensor fields with the new template sensor fields. You have to use one or the other, not a mixture of both.

Change value_template to state.


Reading the docs can be a faster solution than posting in a forum.

Also, in line comments might screw things up. I recommend putting your comment before. Lastly, i’d recommend adding availability template to ensure you don’t get warnings when sensor.gara…doesn’t exist.

  - sensor:
        # Erzeuge Invertierte Gargentor Position
      - name: garagentor_position_invertiert"
        unit_of_measurement: %
        state: "{{ 100 - states('sensor.garagentor_position') | int  }}"
        availability: "{{ states('sensor.garagentor_position') | is_number }}"
1 Like

thanks. But i was not sure, that state is the same as value_template. for me, state is only true or false. but not a number as value.
But it works.

I don’t understand your comment. The name of the field is state. It produces the state of the sensor. In the legacy template sensors, value_template is the name of the field and that produces the state of the sensor. Your configuration is using the new templating style, therefore you should use the new templating style field name that produces the state.

Thanks petro. But states seems to work different then value_template.
Now, if i open my garage door (through knx) the door opens and stops in the middle of the way. After starting again, it stops short before it is fully closed.
After uncommenting the state line, it works, but home assistant doesnt see the state. (thats expected, because its uncommenting)
The main problem is, that the knx garage door module reports 100% as open and HA and knx, and all others see 100% as closed. So i must invert the value to display the correct position.

edit: I see in the knx group monitor, that home assistant is sending a stop command. But why?
With value_template this doesnt happend.
After uncommenting the stop_address in my knx configuration, thet door opens and closes without a problem. But this could not be the solution.

You are 100% confused as to how this works. Template sensors have no impact on your hardware. They are virtual sensors that are supplemental to your original sensor/entity. They only represent a state that you see in the ui and they will not impact your hardware in any way.

1 Like

I’ve switched all my templates over to the new format, but never really noticed the availability option before. I can see where this will make my life a lot easier, if I go back and add it to all my templates.

Thank you!

Yah and you can avoid using defaults

Thats right. I dont really understand templates at the moment.
But for full understanding, what i do at the moment is,

I have an knx entity of type cover which represents my garage door. To represent the right state of the door position, i have a KNX group address. For this group address i have a sensor configured “sensor.garagentor_position”.
I created a template sensor to invert the value of sensor.garagentor_position.
In my knx config i also have an expose entry, which sends the value of the template sensor to my knx group address “inverted position”.

This group address is used in my cover configuration as “position_state_address”.

Before updating, this works like a charme. After the update and also after changing value_template to state, it doesnt work correctly. Because home assistant is send,why ever, stop messages.

That’s impossible (in regards to the template sensor). Your template sensor was not working before your update because value_template has never been valid for the configuration type you used. It would have errored from day one. You must be looking at a false flag and just noticed this error for the first time.

I suggest looking at other aspects of your config that might be driving this difference.

Maybe this just never worked and therefore the Knx Cover was not initialized with any position - and just relied on position calculation and binary open/close.
Now with the fixed template it gets somehow malformed values 🤷