Hi.

This works fine in the template editor:

{% if states('sensor.apollo_mtr_1_cca750_presence_target_count') | int > 0 %}
  Detected
{% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_1_occupancy', 'on') %}
  Detected
{% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_2_occupancy', 'on') %}
  Detected
{% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_3_occupancy', 'on') %}
  Detected
{% else %}
  Not Detected
{% endif %}

But when I try to create a binary_sensory from it in configuration.yaml, I get “‘binary_sensor’ is undefined”:

template:
  - binary_sensor:
    - name: "Lounge Presence"
      state: >-
        {% if states('sensor.apollo_mtr_1_cca750_presence_target_count') | int > 0 %}
          Detected
        {% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_1_occupancy', 'on') %}
          Detected
        {% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_2_occupancy', 'on') %}
          Detected
        {% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_3_occupancy', 'on') %}
          Detected
        {% else %}
          Not Detected
        {% endif %}
      device_class: presence

I’m probably using incorrect syntax or something. Can anyone help me with this?

You are viewing a single thread.
View all comments

I found the solution. configuration.yaml needed to have the following syntax, with the defined values being true or false (instead of “Detected” or “Not Detected”):

template:
  - binary_sensor:
      - name: "Lounge Presence"
        state: >-
          {% if states('sensor.apollo_mtr_1_cca750_presence_target_count') | int > 0 %}
            true
          {% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_1_occupancy', 'on') %}
            true
          {% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_2_occupancy', 'on') %}
            true
          {% elif is_state('binary_sensor.apollo_msr_2_c7bfe8_radar_zone_3_occupancy', 'on') %}
            true
          {% else %}
            false
          {% endif %}
        device_class: presence
permalink
report
reply

homeassistant

!homeassistant@lemmy.world

Create post

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

Community stats

  • 425

    Monthly active users

  • 564

    Posts

  • 5.9K

    Comments

Community moderators