Kia ora everyone,
I’ve recently started using fields in my scripts and it’s been a game changer to cleaning up my automations and all and all making things more tidy. Honestly whoever in the dev team got this working, thank you I’ll shout you a drink someday.
The question I have is in relation to dynamic workflows. The fields section appears to allow for customization by checking or unchecking the required section you can control what is passed onto the sequence section however that’s where it appears to come unstuck.
If I don’t fill in a field however one of the sequence sections is looking for that field to be filled in, whether this be a actionable notification or a standard message, wouldn’t this error with something like {{mobile actionable 2 id}} not found?
I have use cases for both a single actionable notification or multiple choice to be sent to my devices and I’d love to create a script that can handle them both. Can anyone tell me if this is definitely not possible and that I simply need to create different scripts for different amounts of actionable notifications or whether it is actually possible to have one script to rule them all.
Is there a way to do an “if-then” in the sequence like if only one field is filled in then ___ otherwise ___
Sorry if I’m not explaining it well, I find it difficult to explain.
It would be easier to give you a specific answer if you provide an example automation/script configuration.
You can use Templating to check if field variables have been given a value by using the defined
test. This can be used either in a more complex template or directly in a Template condition as part of an If/Then or Choose action’s conditional logic.
Script Example
notify_alexa_random_bird_call:
alias: Notify - Alexa - Bird Call
description: A script to play a selected or random bird call over Alexa
fields:
bird:
name: Bird Name
description: The amount of time to wait before turning on the living room lights
selector:
select:
options:
- Chickadee
- Raven
- Rooster
output:
name: Target Alexa
description: The Alexa device you want to out to.
example: media_player.living_room_dot
required: true
selector:
entity:
filter:
integration: alexa_media
domain: media_player
variables:
random_bird: '{{[''Chickadee'',''Raven'',''Rooster'']|random|lower}}'
birdcall:
chickadee: <audio src="soundbank://soundlibrary/animals/amzn_sfx_bird_chickadee_chirps_01"/>
raven: <audio src="soundbank://soundlibrary/animals/amzn_sfx_raven_caw_2x_01"/>
rooster: <audio src="soundbank://soundlibrary/animals/amzn_sfx_rooster_crow_02"/>
message: |
{% if bird is defined %}
{{ birdcall.get(bird|lower) }}
{% else %}
{{ birdcall.get(random_bird) }}
{% endif %}
sequence:
- service: notify.alexa_media
data:
target: '{{ output }}'
message: '{{ message }}'
data:
type: tts
mode: single
For the proposed notification script you would likely want to use it in a condition of a Choose or If/Then:
...
action:
- choose:
- alias: "Test: If actionable 2 blank"
conditions: "{{ mobile_actionable_2_id is undefined }}"
sequence:
- service: notify.example
....
This is my current script as it stands dpaste/OauDa (YAML)
I’ve also just found this which if i could get it to include options for other notification types such as hass agent and fire tvs that would be perfect 🔔 Notifications - Actionable Mobile Notifications Script, with optional Timeout Feature and Camera Snapshots [works with iOS/Android] - #4 by joe.cole1
Turns out that blueprint doesn’t accept non mobile app notifications so I’m back to writing my own. One issue I’m running into with fields is boolean, RGB colour and select fields don’t appear to be referenced by “{{field_name}}” like text and notification icon can be but i can’t seem to find documentation on how to reference them