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?
Thanks for the suggestion, @NeoNachtwaechter.
But doing that makes configuration.yaml invalid:
Give us the plain English of what you think this is supposed to do first 😉
Your error suggests a yaml formatting issue.
If any of these 4 things happen, set the sensor to “Detected”, otherwise set it to “Not Detected”:
- MTR presence target count is greater than 0 (zero)
- MSR zone 1 occupancy is “on”
- MSR zone 2 occupancy is “on”
- MSR zone 3 occupancy is “on”
As I said, this is working correctly in the template editor. The problem is that I can’t make a sensor out of it.
Okay, but the post being responded to threw an error that certainly seems like a yaml formatting error.
If you simply deleted the “template” portion, and then changed the “binary_sensor” line without correcting the spacing in the lines after that, you’d get this error. Yaml is strict about leading spaces.