#Actionable notifications on iphone
39 messages · Page 1 of 1 (latest)
Here is also an example for a script. The principles also work in automations.
https://companion.home-assistant.io/docs/notifications/actionable-notifications/
I saw this documentation, but I can understand how to build an automation that allow me to turn off a switch
You use the notify service with actions (which have kind of an ID - e.g. OFF and IGNORE), add a wait for trigger (event - mobile_app_notification_action and the action's ID) and continue with a switch turn off action.
Here is an example of an automation reminding to arm the alarm when away.
alias: Alarm away
description: ""
trigger:
- platform: numeric_state
entity_id: zone.home
below: 1
condition:
- condition: not
conditions:
- condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.master
state: armed_custom_bypass
- condition: state
entity_id: alarm_control_panel.master
state: armed_away
- condition: state
entity_id: alarm_control_panel.master
state: triggered
- condition: state
entity_id: alarm_control_panel.master
state: pending
action:
- data:
title: Alarm
message: >-
Alarm is inaktive. So you want to activate it?
data:
color: "#FF0000"
clickAction: noAction
persistent: true
tag: persistent
actions:
- action: ARM_ALARM
title: Arm
- action: IGNORE_ALARM
title: Ignore
action: notify.mobile_app_phone
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: ARM_ALARM
- platform: event
event_type: mobile_app_notification_action
event_data:
action: IGNORE_ALARM
- platform: event
event_type: mobile_app_notification_cleared
event_data:
action_1_key: ARM_ALARM
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == 'ARM_ALARM' }}"
sequence:
- data:
mode: away
skip_delay: true
entity_id: alarm_control_panel.master
enabled: true
action: alarmo.arm
- conditions:
- condition: template
value_template: "{{ wait.trigger.event.data.action == 'IGNORE_ALARM' }}"
sequence:
- stop: Ignored
enabled: true
- conditions:
- condition: template
value_template: >-
{{ wait.trigger.event.event_type ==
'mobile_app_notification_cleared' }}
sequence:
- stop: Ignored
mode: single
Ok, sorry but I am a beginner
Here my code:
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action: - action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notify from Home Assistant
message: Coffee machine is ON for too long!!!
mode: single
How I can integrate?
By adding the actions to the nofify action first
Ok, I wish only a button to turn off the machine
@sturdy pendant To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.
Then add one action to the notify data part.
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action: - action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notifica da Home Assistant
message: La macchina del caffè è accesa da troppo!!!
data:
actions:
- action: OFF_MACHINE
title: Spegni macchina
mode: single
And now you have to build the wait for trigger part
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action: - action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notifica da Home Assistant
message: La macchina del caffè è accesa da troppo!!!
data:
actions:
- action: OFF_MACHINE
title: Spegni macchina
mode: single
To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.
I think this is the part I not understand
It is in my example.
The event trigger mobile_app_notification_action is the one reacting to the action, and mobile_app_notification_cleared is when the notification is swiped away without action press.
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action:
- action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notifica da Home Assistant
message: La macchina del caffè è accesa da troppo!!!
data:
actions:
- action: OFF_MACHINE
title: Spegni macchina
mode: single
2 parts missing.
- the waiting
- the action with a condition
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action:
- action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notifica da Home Assistant
message: La macchina del caffè è accesa da troppo!!!
data:
actions:
- action: TURN_OFF_COFFEE_MACHINE
title: Spegni macchina
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: TURN_OFF_COFFEE_MACHINE
- platform: device
type: turned_off
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
mode: single
I would do this for the wait part
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: TURN_OFF_COFFEE_MACHINE
- platform: event
event_type: mobile_app_notification_cleared
event_data:
action_1_key: TURN_OFF_COFFEE_MACHINE
If I paste this code
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action:
- action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notifica da Home Assistant
message: La macchina del caffè è accesa da troppo!!!
data:
actions:
- action: TURN_OFF_COFFEE_MACHINE
title: Spegni macchina
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: TURN_OFF_COFFEE_MACHINE
- platform: event
event_type: mobile_app_notification_cleared
event_data:
action_1_key: TURN_OFF_COFFEE_MACHINE
mode: single
I get this error: Message malformed: extra keys not allowed @ data['action'][2]['platform']
And then a condition, to just turn off, if the action is pressed
- condition: template
value_template: "{{ wait.trigger.event.data.action == 'TURN_OFF_COFFEE_MACHINE' }}"
Look how I indented the platform things in my example
And at last you just add a switch turn off for your coffee machine
Could you post the code complete? Please I beg you, just to understand how to works
alias: Macchina caffè long
description: ""
trigger:
- platform: device
type: turned_on
device_id: 7f2f1450e0853c7bbf50aa8fbed29ad8
entity_id: dd68fa8c51ca77bbc19ba61f06f98e63
domain: switch
for:
hours: 2
minutes: 0
seconds: 0
condition: []
action:
- action: notify.mobile_app_iphone_11_di_marco
metadata: {}
data:
title: Notifica da Home Assistant
message: La macchina del caffè è accesa da troppo!!!
actions:
- action: TURN_OFF_COFFEE_MACHINE
title: Spegni macchina
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: TURN_OFF_COFFEE_MACHINE
- platform: event
event_type: mobile_app_notification_cleared
event_data:
action_1_key: TURN_OFF_COFFEE_MACHINE
- condition: template
value_template: "{{ wait.trigger.event.data.action == 'TURN_OFF_COFFEE_MACHINE' }}"
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.coffee_machine
mode: single
Or whatever you use to turn off the coffee machine
Ok I paste the code
Message malformed: expected dict for dictionary value @ data['event_data']
I just copied your notify action, assuming it would already have worked. Found the mistake and edited it above
Update: when the notify shows up and I keep press show the button to switch off
Sorry for my english, and thank you so much for the help 🙏
If it is working now, please add the tag "✅Resolved" in the ... menu of this post