Is this possible?
trigger:
- platform: state
entity_id: sensor.house_mode
to:
- 'Occupied'
- 'Guest'
action:
- service:
Is this possible?
trigger:
- platform: state
entity_id: sensor.house_mode
to:
- 'Occupied'
- 'Guest'
action:
- service:
think it should/could work, though not tested.
If that doesn’t work you can defo do it this way:
trigger:
- platform: state
entity_id: sensor.house_mode
to: 'Occupied'
- platform: state
entity_id: sensor.house_mode
to: 'Guest'
@lolouk44
Sorry about the edits. I must have tried to delete my post as you were replying because I suddenly realised the obvious answer which you gave…
Thanks for responding.
Everyone else can ignore this.
Does this work as an OR or an AND argument? Is it possible to work it like the conditions?
this is technically neither, they are triggers, so as long as one of the triggers…triggers, the automation will run.
you’d then need to use conditions if you wanted an AND state.
It works like an ‘or’, but it’s not an or as @lolouk44 said.
@klogg could also use a value template trigger if he wants to shorten the code. And it would be considered an or.
trigger:
- platform: template
value_template: "{{ states('sensor.house_mode') in ['Occupied','Guest'] }}"
yes, always cool to do it that way, so nice to read.
can that be done with multiple entity_id’s too?
like I have now:
trigger:
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
# from: 'not_home'
to: 'home'
for:
seconds: 30
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
# from: 'home'
to: 'not_home'
for:
seconds: 30
tried:
trigger:
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
# from: 'not_home'
to:
- 'home'
- 'not_home'
for:
seconds: 30
but that isn’t accepted unfortunately.
It can be, but not with the for: seconds: 30.
Any specific syntax I need to follow? I get this error:
Invalid config for [automation]: expected str for dictionary value @ data[‘trigger’][0][‘to’]. Got None
when doing this:
- alias: Daughters presence
id: 'Daughters presence'
initial_state: on
trigger:
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
# from: 'not_home'
to:
- 'home'
- 'not_home'
You can’t list in the to: catagory.
has to be either:
trigger:
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
to: 'home'
or
trigger:
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
to: 'not_home'
or to handle both:
trigger:
- platform: state
entity_id:
- device_tracker.1
- device_tracker.2
- device_tracker.3
- device_tracker.4
condition:
- condition: template
value_template: "{{ trigger.to_state.state in ['home','not_home'] }}"
of course! and I already had that in the conditions… should quit the decaf…
for testing purposes I use the imitate variable option in the dev-template.
{{ trigger.to_state.state is not none and
trigger.from_state.state is not none and
trigger.to_state.state is in ['home','not_home']
for example with trigger = device_tracker.iphone. No matter what I try, it error out.
why is that?
using {% set trigger = ‘device_tracker.iphone’%} error: Error rendering template: UndefinedError: 'str object' has no attribute 'to_state'
using {% set trigger = ‘device_tracker.iphone’%} error: Error rendering template: UndefinedError: 'device_tracker' is undefined
{%set trigger.to_state = device_tracker.iphone %} error: Error rendering template: TemplateRuntimeError: cannot assign attribute on non-namespace object
…
what am i doing wrong??
what type of trigger is it?
in this case a device_tracker. But if I use a group in another setting/template I get the same errors, while in several automations this works fine… How to check if a template is valid if one cant test it ?
btw, I had this:
{{trigger.to_state.state is in [‘home’,‘not_home’] }} which works also.
Apparently is in
and in
both do the same
accessing the trigger object will only work inside automation conditions and actions.
You mean one cant test that in the dev_tools? Bummer. How else would I be able to test the difference/errors in this ;_
data_template:
title: 'Presence Tracking:'
message: >
{% if trigger.to_state.state == 'not_home' %}
1- {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}}
{% elif trigger.from_state.state == 'not_home' %}
2- {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
{% elif trigger.from_state.state == 'home' %}
3- {{ trigger.from_state.attributes.friendly_name }} left {{trigger.from_state.state}}
{% elif trigger.to_state.state == 'home' %}
4- {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
{% elif trigger.to_state.state != 'home' %}
5- {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
{% else %}
6- {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}} and arrived at {{trigger.to_state.state}}
{% endif %}
correct, you cannot test any trigger stuff in the dev_tools. You can however emulate it…
in your example, make the triggers into variables for your automation:
{% set name = trigger.to_state.attributes.friendly_name %}
{% set to_state = trigger.to_state.state %}
{% set from_state = trigger.from_state.state %}
{% if to_state == 'not_home' %}
1- {{ name }} left {{ from_state }}
{% elif trigger.from_state.state == 'not_home' %}
2- {{ name }} arrived at {{ to_state }}
{% elif from_state == 'home' %}
3- {{ name }} left {{ from_state }}
{% elif to_state == 'home' %}
4- {{ name }} arrived at {{ to_state }}
{% elif to_state != 'home' %}
5- {{ tname }} arrived at {{ to_state }}
{% else %}
6- {{ name }} left {{ from_state }} and arrived at {{ to_state }}
{% endif %}
then in the editor do things like this:
{% set name = "FOO" %}
{% set to_state = "home" %}
{% set from_state = "not_home" %}
{% if to_state == 'not_home' %}
1- {{ name }} left {{ from_state }}
{% elif trigger.from_state.state == 'not_home' %}
2- {{ name }} arrived at {{ to_state }}
{% elif from_state == 'home' %}
3- {{ name }} left {{ from_state }}
{% elif to_state == 'home' %}
4- {{ name }} arrived at {{ to_state }}
{% elif to_state != 'home' %}
5- {{ tname }} arrived at {{ to_state }}
{% else %}
6- {{ name }} left {{ from_state }} and arrived at {{ to_state }}
{% endif %}
o wow, thats cool. This is going in my templating examples file for sure!
Thank you so very much.
first elif should be this i guess:
{% elif from_state == 'not_home' %}
in stead of
{% elif trigger.from_state.state == 'not_home' %}
so one can emulate, but not use real entity_ids here, not even in this simulation setup? Not sure I understand what this emulating means though. Should it render an outcome, and if yes, were?
I mean you could set it equal to the actual state, but it wouldn’t be triggers.
{% set name = state_attr('xxx.xxx','attr') %}
{% set to_state = states('xxx.xxx') %}
{% set from_state = states('xxx.xxx') %}
ok thanks, glad I understand now.