Templates Broken

Hi!

I have not changed anything in my .config but as of roughly 4 hours ago my templates will no longer display properly in lovelace and they are now showing as invalid using the Check Configuration tool.

I am unable to troubleshoot the issues using the template tool. I have restarted HA and have fully updated without any luck.

Sample template (that was working properly for months up until this afternoon):

      bathroom_livingroom_humidity_difference:
        friendly_name: "Bathroom_Living Room Humidity Difference"
        unit_of_measurement: '%'
        value_template: "{{ ((float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_4.state) - float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity.state))) | round(2) }}"

What is the specific error from the logs?

Try this:

value_template: "{{ ( states('sensor.zooz_zse40_4_in_1_sensor_relative_humidity_4')|float - states('sensor.zooz_zse40_4_in_1_sensor_relative_humidity')|float )|round(2) }}"

I’ve noted now that the templates no longer show up in the logbook and do not appear as entities.

Tediore means what specific error messages do you see in developer tools / logs.

Did you try my version of your template that wont produce errors if the sensor states are unavailable?

Thank you, that works, but I found out that my original value_template does too if the single line is entered in the template tool, it seems the error is somewhere else in the setup.

Sorry- I replied to you just as your message was coming through, thank you for the clarification. Not all of the templates return error messages (though none are appearing as entities), the following template does provide an error:

      house_average_humidity:
        friendly_name: "House Average Humidity"
        unit_of_measurement: '%'
        value_template: "{{ ((float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_3.state) + float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity.state) + float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_2.state + float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_5.state)) / 4) | round(2) }}"

Error rendering template: TemplateSyntaxError: unexpected '}', expected ')'

Sorry, I misunderstood-

Not all of the templates return error messages (though none are appearing as entities), the following template does provide an error:

      house_average_humidity:
        friendly_name: "House Average Humidity"
        unit_of_measurement: '%'
        value_template: "{{ ((float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_3.state) + float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity.state) + float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_2.state + float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_5.state)) / 4) | round(2) }}"

Error rendering template: TemplateSyntaxError: unexpected '}', expected ')'
+ float(states.sensor.zooz_zse40_4_in_1_sensor_relative_humidity_2.state +

You’re missing a closing parenthesis there. You should also consider changing your templates to what Tom listed above (using states() and | float)

Thank you- I have made the suggested change and can confirm that the template works in the editor, but after making the change in .config and restarting the server the template still does not work as an entity. The following is the full entry in my config:

sensor:
  - platform: template
    sensors:
      bathroom_livingroom_humidity_difference:
        friendly_name: "Bathroom_Living Room Humidity Difference"
        unit_of_measurement: '%'
        value_template: "{{ ( states('sensor.zooz_zse40_4_in_1_sensor_relative_humidity_4')|float - states('sensor.zooz_zse40_4_in_1_sensor_relative_humidity')|float )|round(2) }}"

Looks fine to me. So you’re saying you don’t see a sensor.bathroom_livingroom_humidity_difference at developer tools > states? Config check come back ok? Any errors in the log?

Also is that the only sensor: section in your config?

Correct, I do not see the expected entity in developer tools > states. I do have errors in the config that correspond to templates that show up after the one that’s been adjusted, I’m going to try erasing those so only the in progress template is in the config.

The logbook does not include any of my entities (with errors or otherwise), but I do have a notification from three hours ago (roughly corresponds to when I noticed an issue but before I started trying to fix it):

Invalid config
The following integrations and platforms could not be set up:

sensor.template
Please check your config.


Please look at developer tools > logs for errors

Removing all but the re-worked bathroom_livingroom_humidity_difference from my .config has worked and the entity is now available, I will work on rewriting my other templates in the suggested format, thank you!