coming from the old actionable notifications with the ios:
categories, I am faced with a challenge… I don’t really see where to add the new notification in to this script below. The current script runs fine, has a wait_template to await some user action, and if not, simply continues without action.
I’d like to add the Yes/No/Dismiss option to a question “Do you want to switch off the Netwerk Library anyway?” and if yes, run the script that is listed at the end, ‘script.switch_netwerk_library_off’ . I am completely lost though reading https://companion.home-assistant.io/docs/notifications/actionable-notifications#building-notification-action-scripts which seems to make it so complex… What to add, I dont think I need variables at all?
Please help me out here:
prompt_imac_library:
alias: Prompt iMac Library
mode: restart
sequence:
- service: notify.system
data:
title: >
Rpi4: Network Library can't be powered down
message: >
{% if is_state('binary_sensor.imac_library_off','off') %} Switch off iMac Library, might be charging!
{% elif is_state('sensor.hvb_macbook_pro_primary_display_name','DELL U2720Q') %} Turn off your Dell monitor
{% else %} Check power usage in the Library
{% endif %}
# here for the actionable notification?
- wait_template: >
{{is_state('binary_sensor.imac_library_off','on') or
states('sensor.netwerk_library_actueel')|float < 12}}
timeout: '00:15:00'
continue_on_timeout: 'true'
# or here...?
- choose:
conditions: >
{{is_state('binary_sensor.imac_library_off','on') and
states('sensor.netwerk_library_actueel')|float < 12}}
sequence:
service: script.turn_on
target:
entity_id: script.switch_netwerk_library_off
- condition: state
entity_id: input_boolean.notify_system
state: 'on'
- service: notify.system
data:
message: >
{{as_timestamp(now())|timestamp_custom('%X')}}: {{'Switched off iMac library, continuing...'
if is_state('binary_sensor.imac_library_off','on') else
'You need to manually turn off iMac library later'}}
Ive added
- service: notify.mobile_app_calltheboss
data:
message: Do you want to switch off anyway?
data:
push:
badge: 22
actions:
- action: "TURNOFF"
title: "Yes"
destructive: true
- action: "LEAVEBE"
title: "No"
- action: "DISMISS"
title: "Dismiss"
to the first position comment, but nothing is happening after the initial notification…
the automation I tried is:
automation:
- alias: iOS - Network library notification
id: iOS - Network library notification
trigger:
platform: event
event_type: mobile_app_notification_action
action:
choose:
- conditions: >
{{trigger.event.data.action == 'TURNOFF'}}
sequence:
- service: script.turn_on
target:
entity_id: script.switch_netwerk_library_off
- service: notify.mobile_app_calltheboss
data:
push:
badge: 0
title: Netwerk Library
message: Switched off, badge reset
- conditions: >
{{trigger.event.data.action == 'LEAVEBE'}}
sequence:
service: notify.mobile_app_calltheboss
data:
push:
badge: 1
title: Netwerk Library
message: Ok, leave it be
# case DISMISS
default:
service: notify.mobile_app_calltheboss
data:
# push:
# badge: 0
# title: Netwerk Library
message: clear_badge #Dismissed, badge reset
entering the data of the notify in the service page does connect and display the badge and message on the iPhone…
thanks for having a look!
edit
Ive put the above in a separate script and added that in the prompt_imac_library
contain script, and now is works… how’s that for mystery…
edited the automation a bit too:
automation:
- alias: iOS - Network library notification
id: iOS - Network library notification
trigger:
platform: event
event_type: mobile_app_notification_action
action:
choose:
- conditions: >
{{trigger.event.data.action == 'TURNOFF'}}
sequence:
- service: script.turn_on
target:
entity_id: script.switch_netwerk_library_off
- service: notify.mobile_app_calltheboss
data:
data: # <--- needed the double data key
push:
badge: 0
title: Netwerk Library
message: Switched off, badge reset
- conditions: >
{{trigger.event.data.action == 'LEAVEBE'}}
sequence:
service: notify.mobile_app_calltheboss
data:
data:
push:
badge: 1
title: Netwerk Library
message: Ok, leave it be
# case SILENT
default:
service: notify.mobile_app_calltheboss
data:
message: clear_badge