jkaberg
(Joel Kåberg)
June 17, 2024, 11:57am
1
I’m trying to create an automation that pauses another automation if said entity is not triggered by that automation (alas someone pressed the physical cover button) - however the following automation fails to do so
alias: "TV Stua: Administrere screens kortvegg automasjon"
description: ""
trigger:
- platform: state
entity_id:
- automation.ta_ned_kortvegg_screens_ved_sol
from: "on"
for:
hours: 2
minutes: 0
seconds: 0
id: gjennoppta
- platform: state
entity_id:
- cover.screen_kortvegg
id: screen-endret
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- gjennoppta
sequence:
- service: automation.turn_on
target:
entity_id: automation.ta_ned_kortvegg_screens_ved_sol
data: {}
- conditions:
- condition: trigger
id:
- screen-endret
- condition: template
value_template: >-
{{ trigger.to_state.context.id is not none and
trigger.to_state.context.parent_id is none and
trigger.to_state.context.user_id is none }}
sequence:
- service: automation.turn_off
data:
stop_actions: true
target:
entity_id: automation.ta_ned_kortvegg_screens_ved_sol
mode: single
The following jinja code is supposed to detect if an an entity is triggered by an automation, however I’ve observed that this jinja code also becomes true when the cover is triggered by an automation?
{{ trigger.to_state.context.id is not none and trigger.to_state.context.parent_id is none and trigger.to_state.context.user_id is none }}
Automation turn_on is controlling the ability of the automation to check for triggers. It is not triggering it nor is there an auto way to check it it triggered. You would need to program in an event or a helper to monitor that, aside from filtering a state change event or something.
Automation services - Home Assistant .
VPC
June 17, 2024, 2:05pm
3
I use this methodology to grab the Context of what changed an entity.
You do. All automation triggers change the context.
What you need to do is store the context when the switch turns on. You need to check all three contexts as per the table:
[Screenshot 2022-06-21 081430]
Then use that when your no-motion automation runs.
e.g. this triggered template sensor will save the switch context when it turns on:
(configuration.yaml)
template:
- trigger:
- platform: state
entity_id: switch.shelly_1pm_garage_switch_0
to: "on"
sensor:
- na…
The example given sets a new sensor to either of physical
, dashboard_ui
, automation
or unknown
.
I have another automation that turns off the original automation if the context is physical
(example a user flipped a switch).
jkaberg
(Joel Kåberg)
June 18, 2024, 6:22am
4
Updated my automation to use event plattform and the event state_changed as trigger
alias: "TV Stua: Administrere screens kortvegg automasjon"
description: ""
trigger:
- platform: state
entity_id:
- automation.ta_ned_kortvegg_screens_ved_sol
from: "on"
for:
hours: 2
minutes: 0
seconds: 0
id: gjennoppta
- platform: event
event_type: state_changed
event_data:
entity_id: cover.screen_kortvegg
id: screen-endret
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- gjennoppta
sequence:
- service: automation.turn_on
target:
entity_id: automation.ta_ned_kortvegg_screens_ved_sol
data: {}
- conditions:
- condition: trigger
id:
- screen-endret
- condition: template
value_template: >-
{{ trigger.to_state.context.id is not none and
trigger.to_state.context.parent_id is none and
trigger.to_state.context.user_id is none }}
sequence:
- service: automation.turn_off
data:
stop_actions: true
target:
entity_id: automation.ta_ned_kortvegg_screens_ved_sol
mode: single
However I noticed it’s erroring when doing the check against to_state attributes, is that what you’re referring to?
I’m sure @VPC solution will work, but if I could avoid an helper entity for this it would be awesome (less clutter)