Automations: is there a "not" for the state trigger?

Hi,

I want to trigger an automation when an input_select control is not set to a specific value.
Is there something like:

- platform: state
  entity_id: input_select.mycontrol
  state: ! 'auto'

or do I need to use a template trigger for that?

Sebastian

Yes, you have to use a template trigger

1 Like

I thought so, thanks!

Sebastian

Would it work to just trigger it off of any other state in the input select? You can have multiple triggers. So you can trigger off of every option on your input select except auto which would trigger it when it does not equal auto.

Another option is to leave the state option out of the trigger. Just have the platform and entity_id. This will trigger each time the input_select state changes. Then put condition for the states you want the automation to run.

As always, there’s more than one way to do it :slight_smile:
I realized that it would be better to check the input_select state in the condition clause, not as a trigger (doesn’t change much regarding my original question).
I ended up using this:

condition:
  condition: template
  value_template: "{% if not is_state('input_select.housemode', 'auto') %}true{% endif %}"

I think that’s about the most compact way to do this.

Sebastian

5 Likes

If I use the template dev tool and try:
value_template: “{% if not is_state(‘input_select.living_room’, ‘Powered Off’) %}true{% endif %}”
I get value_template: “true”
it’s always true no matter what I change powered off to. If I go the the states page and check, it is “Powered Off”
I’ve also tried, value_template: ‘{{ states.input_select.living_room" != “Powered Off” }}’
which I think used to work.

What am I missing?

I don’t see anything wrong with your syntax.
I can also confirm that the exampe I posted above does work for me.
Check for typos - also in the name of the input_select control.
I noticed that your code returns true for me too - and I don’t even have an input_select named living_room.
When in doubt, use the dev tool to display all the current values/states for the variables involved.

Sebastian

You can try your template at YOUR_IP:8123/dev-template

I tried your code on my system and it also returns true even though I don’t have housemode.

Yes I am testing this with YOUR_IP:8123/dev-template

It should return true if the state does not exist, so that is correct.

What is the output of
{{ states.input_select.living_room.state }}

I know - what I was trying to say was, that the code returns true even if the condition you want to check might never actually be checked, because of a typo (and thus you’re actually checking against an undefined object without noticing).
The “not” operator is particularly dangerous here - because at least I subconsciously always have the feeling that “it’s working” when “stuff” returns true…
So when working with templates, I’d always use the dev-tool to verify the values of all variables involved and do a few test runs with different input values (e.g. slider/switch settings) to make sure everything behaves as expected.

Sebastian

1 Like

Thank you. When I upgraded harmony awhile back, the name changed from living_room to livingroom. I should have caught that.

value_template: "{% if not is_state('input_select.livingroom', 'Powered Off') %}true{% endif %}"
returns value_template: “”
If I changed any letter in Powered Off it then returns true.

{{ states.input_select.livingroom.state }}
returns Powered Off

value_template: '{{ states.input_select.livingroom.state != "Powered Off" }}'
value_template: 'False'

It should be good now

I am trying to build a notification when a sensor does not show Off.
This piece of code returns the right value know (thanks to the guidance above):

"{% if not is_state('media_player.woonkamer_audio', 'off') %}true{% endif %}"

With this knowledge I want to build an automation task with this “not” statement. So if the value is not Off it should send a message to Slack.

How do I configure this as automation task in hassio?

I cannot enter a value at “Value template”