home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.77k stars 30.02k forks source link

Template Sensor not working #126866

Open F-i-n-c-h opened 2 hours ago

F-i-n-c-h commented 2 hours ago

The problem

I want to set up a new binary sensor as a tool to combine some window sensors, but my code is not working. I have checked the code in the developer tools and with some additional debug messages. (sz_nachbarraum_durchzug)

In the developer tools the sensor works, but in Home Assistant the sensor value is always “false”. After some tests I check the basic sensor function with the following code (test_template_sensor) - but the sensor value is also always "false".

I have also tested the code on a new image of home assistant (Pi4+sd-card) and with the vdi image (Virtualbox) from the Home assistant website with the same result.

What version of Home Assistant Core has the issue?

2024.9.3

What was the last working version of Home Assistant Core?

?

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Template

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

- platform: template
  sensors:
    sz_nachbarraum_durchzug:
      friendly_name: "SZ Nachbarraum Durchzug"
      value_template: >
        {%- set list_1 = [
          states('binary_sensor.flurfenster'),
          states('binary_sensor.flurtur')
        ] %}
        {%- set list_2 = [
          states('binary_sensor.wohnzimmerfenster')
        ] %}

        {%- set list_1_condition = is_state('binary_sensor.schlafzimmertur', 'on') %}
        {%- set list_2_condition = is_state('binary_sensor.wohnzimmertur', 'on') and is_state('binary_sensor.schlafzimmertur', 'on') %}

        {%- set list_1_active = list_1 | select('eq', 'on') | list | length > 0 %}
        {%- set list_2_active = list_2 | select('eq', 'on') | list | length > 0 %}

        {%- set list_1_available = list_1 | select('ne', 'available') | list | length == list_1 | length %}
        {%- set list_2_available = list_2 | select('ne', 'available') | list | length == list_2 | length %}

        {# Debug-Ausgaben #}
        {{ 'list_1: ' ~ list_1 }}
        {{ 'list_2: ' ~ list_2 }}
        {{ 'list_1_condition: ' ~ list_1_condition }}
        {{ 'list_2_condition: ' ~ list_2_condition }}
        {{ 'list_1_active: ' ~ list_1_active }}
        {{ 'list_2_active: ' ~ list_2_active }}
        {{ 'list_1_available: ' ~ list_1_available }}
        {{ 'list_2_available: ' ~ list_2_available }}

        {% if (list_1_condition and list_1_active and list_1_available) or
              (list_2_condition and list_2_active and list_2_available) %}
          {{ 'Result: true' }}
          true
        {% else %}
          {{ 'Result: false' }}
          false
        {% endif %}
      delay_on: "00:05:00"
      delay_off: "00:01:00"

- platform: template
  sensors:
    test_template_sensor:
      friendly_name: "Test Template Sensor"
      value_template: >
        {% if true %}
          true
        {% else %}
          false
        {% endif %}

Anything in the logs that might be useful for us?

No response

Additional information

No response

mib1185 commented 2 hours ago

Hi @F-i-n-c-h

We use GitHub for tracking issues with Home Assistant Core itself, not for providing support - so if you could provide more details like logs or any other helpful diagnostics data or error details or steps how to reproduce or your configuration, than we can handle it as an issue report, else it is a support request and you should try our Community Forum or join our Discord chat server.

Thanks! 👍