Templates misbehaving in 2023.5

There’s nothing that will make that template fail. Check your logs for errors. You don’t need to switch the template over from legacy to the ‘new’ style. It should work out of the box without fail. Something else is causing the entity to no longer load.

Looking at that specific template, the only way it would fail is if your source sensor was missing. And even then, it wouldn’t fail, it would just be unknown until it was found again.

It doesn’t fail, just it always states “unknown” state.

Then your source sensor most likely doesn’t exist… Please share a screenshot of the source sensor in developer tools → states page.

A screenshot of this entity 'sensor.komfovent_on_off_num'

i reverted back to previous ha core version right now, but i will update it once again tommorrow. Meanwhile configuration of that sensor itself looks like this:

  sensors:
    - name: "Komfovent on off num"
      address: 0
      input_type: holding
      data_type: uint16
      scan_interval: 5

That’s not what I asked for. I’m very confident that your entity was not being created and you were looking at the template being the problem when you should have been looking at the source. So when you update, please look at developer tools → states page for your sensor.komfovent_on_off_num sensor and verify it’s working.

1 Like

After the update, that sensor was showing numeric state as intended, but it seems that mapper didn’t map that next sensor based on numeric state, but i will double check that again.

Sorry, but a template wouldn’t just fail like that. I know I keep hammering on this, but did you look at the sensor in developer tools → states page? Or did you look at it elsewhere? If the entity_id changed, that template wouldn’t know about it. The entire UI hides the entity_id behind the friendly name except for the developer tools → states page. So that’s where you need to look.

1 Like

Like that but use an availability template. IF you need help with it start a new post.

Here are the screenshots from devtools → states page:

Please show a screenshot with the entit_id. That’s still showing the friendly name, not the entity_id. Just take a screenshot of the entity and it’s states and attributes in the table, not in the set state area.

is this want you want ?

1 Like

Please paste {{ states('sensor.komfovent_on_off_num') }} in developer tools → states.

Remove that. You’ll probably find a related message in your logs.

Note that your sensor state is "unknown", not the "Unknown" fallback value from your template.

As another hint, it’s a bit dangerous using a reserved word like state for a variable in your template. It seems to work for me in the template editor, but can be a bit risky.

Please also paste your template into the template editor and see if it returns what you’d expect. Like this, which returns Unknown for me because I don’t have your sensor:

My guess is it’ll work there, but it’s failing as a sensor because of your unit_of_measurement in the config.

Then turn that one into a binary sensor as recommended.

state should be good, states is the risky override.

Perfect. Now works. Appreciate the help.

I have just upgraded Homeassistant Core from 2023.4.6 to 2023.5.3 and notice that the following sensor (example) show Unknown in the UI while the value_template shows the correct output “Result type: string” value in the Jinja2 template engine. I have experimented with new template format, adding device class etc. but can’t lay my hands on the necessary correction. I have reverted back to 2023.4.6 and all time (hr:min) outputs are shown again.
Any advice welcome!

- platform: template
  sensors:
    livingroom_light_off:
      friendly_name: Light OFF
      value_template: >-
        {% if is_state('input_boolean.livingroom_light_auto', 'on') %}
        {{states('input_datetime.livingroom_light_not_after_time').rsplit(':',1)[0] }}
        {% else %}
            -
        {% endif %}
      icon_template: mdi:av-timer
      unit_of_measurement: "hr" 


2023.4.6


2023.5.3

It’s because you’re returning a non-numerical result with a unit_of_measurement. Remove the unit_of_measurement and add the hr to your state.

Thanks for the quick turnaround and the solution. Confirm success. However, the statement “add the hr to your state” I don’t immediately grasp.

value_template outputs your state, just add hr at the end of your template where you’re outputting the time.

All solved. Thank you so much!