HI, I’m not sure where to post such a request, but I certainly would like something to be in the official starting guide of homeassistant. Especialy since this is a function that is available, working and simply not documented - at least I haven’t found it and was searching google up and down to find it.
That function is “not is_state”. Perhaps others too, I have only tested this one yet.
What it is capable of is to be used as a condition in order to trigger an event only if said state is NOT true.
The automation in which I am using this one is a light switch which turns off all lights if noone is at home (triggered every time someone leaves “zone.home”). Before I simply used “if state not_home”, but since I have integrated location service Owntracks and Mosquitto onto my computer, I have more states (zones) which makes it impossible to purely rely on “not_home”. Instead I need a “condition: not is_state home”. The lines of code look like this:
trigger:
- platform: zone
entity_id: device_tracker.NAME
zone: zone.home
event: leave
- platform: zone
entity_id: device_tracker.OTHER_NAME
zone: zone.home
event: leave
condition:
- condition: template
value_template: "{{ not is_state('device_tracker.NAME', 'home') }}"
- condition: template
value_template: "{{ not is_state('device_tracker.OTHER_NAME', 'home') }}"
action:
- service: scene.turn_on
entity_id: scene.all_lights_off
As said, this only is true if everyone is away, which in my automation continues to trigger lights off.
I also successfully used it to send me a notification using template-text:
action:
- service_template: notify.notify
data_template:
title: Test
message: |
{% if not is_state("device_tracker.NAME", "home") %}Not Home{% else %}ELSE{% endif %}
As far as I can tell everything is fine with this kind of coding and it saves me a lot of trouble with other automations of this kind too, because it is way easier than to keep track of all other possible options that (in that case) a state could be, especialy since I would ALWAYS have to update ALL automations whenever I add another zone to my map.
I hope you guys find that one helpful and add it to the starting guide too.
Thanks!