Hi Everyone,
I’ve probably just been up too late and missing something obvious. TL;DR I can’t get this condition to execute correctly in the Developer Tools - Template Editor:
NOTE: I have already tried all the combinations of single and double-quotes in the test condition as well as the resulting string, making the condition the same as the result, opposite, etc. I highly doubt it’s a quote-related issue at this point.
- sensor:
- name: "lock status"
state: >
{% if is_state('sensor.exterior_door_lock_status', 'locked') %}
"locked"
{% else %}
"unlocked"
{% endif %}
As you can see in this side-by-side screenshot, my template sensor’s state says "locked"
in the Developer Tools - State, but my test in the Developer Tools - Template Editor evaluates to "unlocked"
.
Long story short, the reason why I’m creating a sensor to read the status of my locks is because I intentionally want the state to return "Unknown"
with a different icon than lock
or lock-open
when one door is locked and the other is unlocked. The plan is for the lock-off
icon to inform the user of this condition, and the lovelace button card to execute a script that locks both doors if the state is unlocked
or unknown
and unlocks both doors if, and only if, both of their states are locked
. Here’s the script this test will be incorporated into for your reference:
alias: toggle_exterior_door_locks
sequence:
- service: |
{% if is_state('sensor.exterior_door_lock_status', 'locked') %}
script.unlock_exterior_doors
{% else %}
script.lock_exterior_doors
{% endif %}
mode: single
icon: mdi:lock
The following code is working correctly, but in case it’s relevant here’s the code for my template sensor that I have in my configuration.yaml
:
template:
- sensor:
- name: "Exterior door lock status"
state: >
{% if is_state('lock.assure_touchscreen_deadbolt_front_door', 'locked') and is_state('lock.assure_key_free_lever_touchscreen_back_door', 'locked') %}
"locked"
{% elif is_state('lock.assure_touchscreen_deadbolt_front_door', 'unlocked') and is_state('lock.assure_key_free_lever_touchscreen_back_door', 'unlocked') %}
"unlocked"
{% else %}
"unknown"
{% endif %}
icon: >
{% if is_state('lock.assure_touchscreen_deadbolt_front_door', 'locked') and is_state('lock.assure_key_free_lever_touchscreen_back_door', 'locked') %}
mdi:lock
{% elif is_state('lock.assure_touchscreen_deadbolt_front_door', 'unlocked') and is_state('lock.assure_key_free_lever_touchscreen_back_door', 'unlocked') %}
mdi:lock-open
{% else %}
mdi:lock-off
{% endif %}