this post was submitted on 01 Nov 2024
10 points (100.0% liked)

homeassistant

11990 readers
12 users here now

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

founded 1 year ago
MODERATORS
10
Assistance creating a sensor (lemmy.thewooskeys.com)
submitted 3 days ago* (last edited 3 days ago) by [email protected] to c/[email protected]
 

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 comment's thread
view the rest of the comments
[โ€“] [email protected] 1 points 3 days ago (1 children)

Move everything back two spaces. You may need a yaml linter. Your problem is just the format from what I'm seeing.

[โ€“] [email protected] 1 points 3 days ago* (last edited 2 days ago)

I think Studio Code Server is a linter. It's telling me what the syntax problems are - I just don't know how to fix them. Now that I removed the hypehn, it's not telling me there are any spacing/formatting issues. But it currently says I'm missing the "entities" and "platform" properties, but I don't know what the values should be. And It also says "state" is not an allowed property, but that's the property that holds all the important stuff about this sensor - so how can I remove it?