Hi, I have a script “Snooze Notification User” with a field “duration” of type “Duration”.
On my main dashboard, each of my family members have a tab with their own settings. The visibility is set using the logged in user.
On the user’s settings tab, i have added a button to launch my script using a custom:mushroom-template-card.
(There’s only one way, i have found so far, that force the user to set the duration before running the script and its by showing the “more info” dialog)
Currently, when the script is executed, I find the logged in user and perform action based on that.
The admin user have access to every user’s settings tab. I use the “admin user” to modify their settings temporarily.
Obviously, the script doesn’t work properly when using this admin user.
My question/issue:
Where I have defined the button to launch the script, I would like the user to select the duration AND pass the username using the appropriate data/variable yaml configuration. I haven’t figured out how to do both at the same time.
If you have better ways to do any of this, let me know.
Here’s the yaml of the entire section, in the dashboard, that each user have.
The card launching the script is the custom:mushroom-template-card with the entity: script.snooze_notification_user
type: grid
cards:
- type: heading
heading: Notification
- type: vertical-stack
cards:
- type: custom:mushroom-template-card
primary: Snooze
secondary: ""
icon: mdi:timer-cog-outline
entity: script.snooze_notification_user
tap_action:
action: more-info
hold_action:
action: more-info
double_tap_action:
action: more-info
icon_color: ""
multiline_secondary: false
fill_container: false
- type: custom:mushroom-template-card
primary: >-
{% if states('input_boolean.motion_notification_enabled_sebastien') ==
'on' %}
Enabled
{% else %}
Disabled
{% endif %}
secondary: ""
icon: mdi:bell-outline
entity: input_boolean.motion_notification_enabled_sebastien
icon_color: >-
{% if states('input_boolean.motion_notification_enabled_sebastien') ==
'on' %}
green
{% else %}
red
{% endif %}
layout_options:
grid_columns: 2
grid_rows: auto
- type: vertical-stack
cards:
- type: custom:mushroom-entity-card
entity: input_boolean.motion_notification_person_sebastien
name: Person
icon: mdi:walk
- type: custom:mushroom-entity-card
entity: input_boolean.motion_notification_pet_sebastien
name: Pet
icon: mdi:dog-side
- type: custom:mushroom-entity-card
entity: input_boolean.motion_notification_vehicle_sebastien
icon: mdi:car
name: Vehicle
layout_options:
grid_columns: 2
grid_rows: auto
column_span: 1
And here is the script as reference. I cleaned it quickly. The original had a field number_of_hours with a default value to ensure i wasn’t setting the datetime to “now”.
alias: Snooze notification - user
sequence:
- variables:
username: >-
{% set username = (states.person |
selectattr('attributes.user_id','==', context.user_id) | map(attribute
= 'name') | list)[0] %}{{username}}
delta: >-
{% set ns = namespace(data={}) %}
{% set ns.data = {"days": 0, "hours": 0, "minutes": 0, "seconds": 0 }
%}
{% if duration is defined %}
{% set new_dict = {"days": duration.days, "hours": duration.hours, "minutes": duration.minutes, "seconds": duration.seconds } %}
{% set ns.data = dict(ns.data, **new_dict) %}
{%endif%}{{ns.data}}
alias: Define Variables
- if:
- condition: template
value_template: "{{username == 'MyAdminUser' }} "
then:
- stop: No personal settings for MyAdminUser
- action: input_datetime.set_datetime
metadata: {}
data:
timestamp: >-
{{ as_timestamp(now() + timedelta(days = delta.days, hours =
delta.hours, minutes = delta.minutes, seconds = delta.seconds))}}
target:
entity_id: input_datetime.motion_notification_snooze_{{username | lower}}
enabled: true
alias: Set the input_datetime
- action: input_boolean.turn_off
target:
entity_id: input_boolean.motion_notification_enabled_{{username | lower}}
data: {}
alias: Turn Off Toggle snooze - user
enabled: true
fields:
duration:
selector:
duration:
enable_day: true
name: Duration
description: The snooze duration
default:
hours: 0
minutes: 0
seconds: 0
required: false
mode: parallel
description: Snooze wyze notifications for current user
max: 10