mase
February 5, 2025, 10:38pm
1
hey guys,
i´m trying to make an automation that´s called by an actionable notification to open or close a cover of a window that is open. however i can´t get it working. maybe someone has an idea or even a better way to do it.
the notification:
action: notify.mobile_app_iphone_david
data:
message: Fenster erkannt! Was möchtest du tun?
data:
actions:
- action: open
title: open
- action: close
title: close
since i have 9 windows i think using a variable like this makes it more easy:
covers:
window_hallway_contact: cover.hallway
window_bedroom_1_contact: cover.bedroom_1
window_bedroom_2_contact: cover.bedroom_2
window_office_1_contact: cover.office_1
window_office_2_contact: cover.office_2
window_livingroom_1_contact: cover.livingroom_1
window_livingroom_2_contact: cover.livingroom_2
window_livingroom_3_contact: cover.livingroom_3
door_balcony_contact: cover.balcony
this is the automation i have right now, that´s not working:
alias: "Fensterstatus Rolladensteuerung"
trigger:
- platform: event
event_type: mobile_app_notification_action
action:
- variables:
action: "{{ trigger.event.data.action }}"
covers:
window_hallway_contact: cover.hallway
window_bedroom_1_contact: cover.bedroom_1
window_bedroom_2_contact: cover.bedroom_2
window_office_1_contact: cover.office_1
window_office_2_contact: cover.office_2
window_livingroom_1_contact: cover.livingroom_1
window_livingroom_2_contact: cover.livingroom_2
window_livingroom_3_contact: cover.livingroom_3
door_balcony_contact: cover.balcony
- repeat:
for_each: "{{ covers.keys() | select('is_state', 'on') | list }}"
sequence:
- service: "cover.{{ 'open_cover' if action == 'open' else 'close_cover' }}"
target:
entity_id: "{{ covers[repeat.item] }}"
mode: parallel
mase:
covers.keys()
The keys are not entity IDs… so | select('is_state', 'on')
doesn’t know what to do with them.
Also, be aware that your trigger is not very specific, so this automation will run every time you activate any notification action. That is one of the reasons why the examples in the companion app docs use Wait for Trigger actions instead of separate automations for actionable notifications.
mase
February 6, 2025, 11:42am
3
that´s something chatgpt gave me since i couldn´t figure it out
i know that it runs everytime, it was just to figure it out. however i didn´t manage…
right now i think it would be easier to make 2 scripts: one that would open the cover and one that would close it. and call the scripts by the action “open” or “close”. however i also can´t get one of the scripts working
mase
February 6, 2025, 3:22pm
4
came up with this automation, guess it´s not the prettiest way to do it, but it works.
so if someone knows a better way (getting rid of all the if/then, maybe using variables) would be nice if he could post it.
alias: Fenster Rolladensteuerung via Mobile Notification
triggers:
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: open
id: open
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: close
id: close
actions:
- choose:
- conditions:
- condition: trigger
id:
- open
sequence:
- action: notify.mobile_app_iphone_david
metadata: {}
data:
message: open
- if:
- condition: state
entity_id: binary_sensor.window_hallway_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.hallway
- if:
- condition: state
entity_id: binary_sensor.window_bedroom_1_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.bedroom_1
enabled: false
- if:
- condition: state
entity_id: binary_sensor.window_bedroom_2_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.bedroom_2
- if:
- condition: state
entity_id: binary_sensor.window_office_1_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.office_1
- if:
- condition: state
entity_id: binary_sensor.window_office_2_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.office_2
- if:
- condition: state
entity_id: binary_sensor.window_livingroom_1_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.livingroom_1
- if:
- condition: state
entity_id: binary_sensor.window_livingroom_2_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.livingroom_2
- if:
- condition: state
entity_id: binary_sensor.window_livingroom_3_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.livingroom_3
- if:
- condition: state
entity_id: binary_sensor.door_balcony_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 100
target:
entity_id: cover.balcony
- conditions:
- condition: trigger
id:
- close
sequence:
- action: notify.mobile_app_iphone_david
metadata: {}
data:
message: close
- if:
- condition: state
entity_id: binary_sensor.window_hallway_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.hallway
- if:
- condition: state
entity_id: binary_sensor.window_bedroom_1_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.bedroom_1
enabled: false
- if:
- condition: state
entity_id: binary_sensor.window_bedroom_2_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.bedroom_2
- if:
- condition: state
entity_id: binary_sensor.window_office_1_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.office_1
- if:
- condition: state
entity_id: binary_sensor.window_office_2_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.office_2
- if:
- condition: state
entity_id: binary_sensor.window_livingroom_1_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.livingroom_1
- if:
- condition: state
entity_id: binary_sensor.window_livingroom_2_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.livingroom_2
- if:
- condition: state
entity_id: binary_sensor.window_livingroom_3_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.livingroom_3
- if:
- condition: state
entity_id: binary_sensor.door_balcony_contact
state: "on"
then:
- action: cover.set_cover_position
metadata: {}
data:
position: 20
target:
entity_id: cover.balcony
mode: parallel
Your original script will work if you change the keys to the actual entity IDs… so instead of window_hallway_contact:
it would be binary_sensor.window_hallway_contact:
Alternatively, you could append the the binary_sensor.
string to each key in the for_each
template, but that would require a loop and the use of a namespace.
In either case and for long-term stability, I would suggest you change the action titles in the calling automation to something more unique like “open_alles_fenster_rolladen”. Make sure to update the trigger(s) and the service
template in the repeat to match whatever you change it to.
mase
February 6, 2025, 5:22pm
6
thanks alot, couldn´t have figured that out on my own!
here is the working code:
alias: Fenster Rolladensteuerung via Mobile Notification
description: ""
triggers:
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: open
id: open
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: close
id: close
actions:
- variables:
action: "{{ trigger.event.data.action }}"
covers:
binary_sensor.window_hallway_contact: cover.hallway
binary_sensor.window_bedroom_1_contact: cover.bedroom_1
binary_sensor.window_bedroom_2_contact: cover.bedroom_2
binary_sensor.window_office_1_contact: cover.office_1
binary_sensor.window_office_2_contact: cover.office_2
binary_sensor.window_livingroom_1_contact: cover.livingroom_1
binary_sensor.window_livingroom_2_contact: cover.livingroom_2
binary_sensor.window_livingroom_3_contact: cover.livingroom_3
binary_sensor.door_balcony_contact: cover.balcony
- choose:
- conditions:
- condition: trigger
id:
- open
sequence:
- repeat:
for_each: "{{ covers.keys() | select('is_state', 'on') | list }}"
sequence:
- target:
entity_id: "{{ covers[repeat.item] }}"
data:
position: 100
action: cover.set_cover_position
- conditions:
- condition: trigger
id:
- close
sequence:
- repeat:
for_each: "{{ covers.keys() | select('is_state', 'on') | list }}"
sequence:
- target:
entity_id: "{{ covers[repeat.item] }}"
data:
position: 20
action: cover.set_cover_position
mode: parallel