AutomationDataset/jianyu-li/jianyu-li_automations.yaml

311 lines
10 KiB
YAML

- alias: 'Jarvis: Voice Timer Cancel'
description: Cancel the current Jarvis timer via voice
triggers:
- command:
- cancel timers
- stop timers
- delete timers
- cancel all timers
- stop all timers
- delete all timers
trigger: conversation
actions:
- action: input_text.set_value
alias: Clear timer data
data:
value: ''
target:
entity_id:
- input_text.jarvis_timer_data
- input_text.jarvis_timer_data_2
mode: single
- alias: 'Jarvis: Voice Timer Cancel Specific'
description: Cancel a specific Jarvis timer by number or by label
triggers:
- command:
- cancel the timer
- cancel the first timer
- cancel first timer
- cancel the second timer
- cancel second timer
- cancel the {label} timer
- cancel {label} timer
- stop the timer
- stop first timer
- stop second timer
- stop the {label} timer
- stop {label} timer
trigger: conversation
actions:
- alias: Call Gemini to parse cancel intent
data:
prompt: "The user wants to cancel a timer. Return ONLY this JSON:\n{\n \"index\"\
: 1,\n \"label\": \"chicken\"\n}\n• \"index\" can be 1, 2, etc.; omit it\
\ if not said\n• Omit \"label\" if not said\nInput: \"{{ trigger.sentence\
\ }}\"\n"
response_variable: jarvis_cancel_response
action: google_generative_ai_conversation.generate_content
- variables:
parsed: "{% set raw = jarvis_cancel_response %} {% if raw is mapping and raw.text\
\ is defined %}\n {{ raw.text | replace('```json','') | replace('```','')\
\ | trim | from_json }}\n{% elif raw is string %}\n {{ raw | from_json\
\ }}\n{% else %}\n {{ raw }}\n{% endif %}"
timer1_pairs: "{% set raw = state_attr('sensor.jarvis_timer', 'sorted_all')\
\ %} {% if raw is string %}\n {{ raw | from_json }}\n{% elif raw is none\
\ %}\n []\n{% else %}\n {{ raw }}\n{% endif %}"
timer2_pairs: "{% set raw = state_attr('sensor.jarvis_timer_2', 'sorted_all')\
\ %} {% if raw is string %}\n {{ raw | from_json }}\n{% elif raw is none\
\ %}\n []\n{% else %}\n {{ raw }}\n{% endif %}"
timer1_labels: '{{ timer1_pairs | map(attribute=1) | map(attribute=''timerLabel'')
| list }}'
timer2_labels: '{{ timer2_pairs | map(attribute=1) | map(attribute=''timerLabel'')
| list }}'
timer1_has_label: "{{ parsed.label is defined and\n (parsed.label | lower)\
\ in (timer1_labels | map('lower') | list) }}"
timer2_has_label: "{{ parsed.label is defined and\n (parsed.label | lower)\
\ in (timer2_labels | map('lower') | list) }}"
- choose:
- conditions:
- condition: template
value_template: '{{ parsed.index | default(0) | int == 1 }}'
sequence:
- action: script.jarvis_cancel_timer_1
data: {}
- conditions:
- condition: template
value_template: '{{ parsed.index | default(0) | int == 2 }}'
sequence:
- action: script.jarvis_cancel_timer_2
data: {}
- conditions:
- condition: template
value_template: '{{ timer1_has_label }}'
sequence:
- action: script.jarvis_cancel_timer_1
data: {}
- conditions:
- condition: template
value_template: '{{ timer2_has_label }}'
sequence:
- action: script.jarvis_cancel_timer_2
data: {}
mode: single
- alias: 'Jarvis: Voice Timer Request'
description: Trigger a timer via voice using Gemini + Assist
triggers:
- command:
- set a timer
- set a timer for {duration}
- start a {duration} timer
- set a {duration} timer
- start a {label} timer for {duration}
- set a {label} timer for {duration}
- start a timer for {duration}
- start a timer for {duration} for {label}
- set a timer for {duration} for {label}
- create a {label} timer for {duration}
- create a {duration} timer
- timer for {duration}
trigger: conversation
actions:
- alias: Call Gemini to extract timer info
action: google_generative_ai_conversation.generate_content
response_variable: jarvis_timer_response
data:
prompt: "The user wants to set a timer. Return ONLY this JSON:\n{\n \"minutes\"\
: 10,\n \"label\": \"pizza\"\n}\n\nRules:\n• \"an hour\" → 60\n• \"half an\
\ hour\" → 30\n• \"90 seconds\" → 2\n• Round up to the nearest whole minute\n\
• Omit \"label\" if none is said\n\nInput: \"{{ trigger.sentence }}\"\n"
- alias: Parse JSON
variables:
parsed: "{{\n (\n jarvis_timer_response.text\n | replace('```json', '')\n\
\ | replace('```', '')\n | trim\n ) | from_json\n}}\n"
- alias: Build timer object
variables:
minutes: '{{ (parsed.minutes | float(0)) | round(0, ''ceil'') | int }}'
label: "{% if parsed.label is defined and parsed.label | trim != '' %}\n {{\
\ parsed.label }}\n{% else %}\n {{ minutes }} Minute Timer\n{% endif %}\n"
now_ts: '{{ now().timestamp() | int }}'
trigger_time: '{{ (now_ts * 1000) + (minutes * 60 * 1000) }}'
timer_id: '{{ ''jarvis-'' ~ now_ts }}'
timer_obj: "{{\n {\n \"id\": timer_id,\n \"status\": \"ON\",\n \"\
createdDate\": now_ts * 1000,\n \"originalDurationInMillis\": minutes *\
\ 60000,\n \"triggerTime\": trigger_time,\n \"remainingTime\": minutes\
\ * 60000,\n \"timerLabel\": label\n } | tojson\n}}\n"
- alias: Save timer to the appropriate slot
choose:
- conditions:
- condition: template
value_template: '{{ states(''sensor.jarvis_timer'') in [''unknown'', ''unavailable'']
}}'
sequence:
- action: input_text.set_value
target:
entity_id: input_text.jarvis_timer_data
data:
value: '{{ timer_obj }}'
- conditions:
- condition: template
value_template: '{{ states(''sensor.jarvis_timer_2'') in [''unknown'', ''unavailable'']
}}'
sequence:
- action: input_text.set_value
target:
entity_id: input_text.jarvis_timer_data_2
data:
value: '{{ timer_obj }}'
mode: single
- alias: 'Notification: Jarvis Timer Done'
description: Sends a notification when the Jarvis timer ends, including the label
triggers:
- entity_id:
- sensor.jarvis_timer
id: timer1
to: unknown
trigger: state
for:
hours: 0
minutes: 0
seconds: 2
- entity_id:
- sensor.jarvis_timer_2
id: timer2
to: unknown
trigger: state
for:
hours: 0
minutes: 0
seconds: 2
conditions:
- condition: not
conditions:
- condition: state
entity_id: input_select.mode
state: Night
- condition: or
conditions:
- condition: template
value_template: '{{ states(''input_text.jarvis_timer_data'') not in ['''', ''unknown'']
}}'
alias: Jarvis Data is not blank
- condition: template
value_template: '{{ states(''input_text.jarvis_timer_data_2'') not in ['''',
''unknown''] }}'
alias: Jarvis Data 2 is not blank
actions:
- choose:
- conditions:
- condition: trigger
id:
- timer1
sequence:
- variables:
label: "{{\n (states('input_text.jarvis_timer_data') | from_json).timerLabel\n\
\ if states('input_text.jarvis_timer_data') not in ['', 'unknown']\n\
\ else 'Your timer'\n}}"
- parallel:
- action: chime_tts.say
metadata: {}
target:
entity_id: media_player.kitchen_homepod
data:
chime_path: /config/www/sounds/timer_end.wav
language: en-GB
message: '{{ label }} is done.'
tts_platform: cloud
voice: EthanNeural
volume_level: 0.75
- action: notify.mobile_app_your_iphone
data:
data:
push:
sound:
critical: 1
name: wheels_of_time.caf
volume: 0
tag: timer_notification
message: '{{ label }} has ended.'
title: Timer Done
- action: notify.mobile_app_someoneelses_iphone
data:
data:
push:
sound:
critical: 1
name: wheels_of_time.caf
volume: 0
tag: timer_notification
message: '{{ label }} has ended.'
title: Timer Done
- action: input_text.set_value
metadata: {}
target:
entity_id: input_text.jarvis_timer_data
data:
value: ''
- conditions:
- condition: trigger
id:
- timer2
sequence:
- variables:
label: "{{\n (states('input_text.jarvis_timer_data_2') | from_json).timerLabel\n\
\ if states('input_text.jarvis_timer_data_2') not in ['', 'unknown']\n\
\ else 'Your timer'\n}}"
- parallel:
- action: chime_tts.say
metadata: {}
target:
entity_id: media_player.kitchen_homepod
data:
chime_path: /config/www/sounds/timer_end.wav
language: en-GB
message: '{{ label }} is done.'
tts_platform: cloud
voice: EthanNeural
volume_level: 0.75
- action: notify.mobile_app_your_iphone
data:
data:
push:
sound:
critical: 1
name: wheels_of_time.caf
volume: 0
tag: timer_notification
message: '{{ label }} has ended.'
title: Timer Done
- action: notify.mobile_app_someoneelses_iphone
data:
data:
push:
sound:
critical: 1
name: wheels_of_time.caf
volume: 0
tag: timer_notification
message: '{{ label }} has ended.'
title: Timer Done
- action: input_text.set_value
metadata: {}
target:
entity_id: input_text.jarvis_timer_data_2
data:
value: ''
- delay:
hours: 0
minutes: 5
seconds: 0
- parallel:
- action: notify.mobile_app_your_iphone
data:
message: clear_notification
data:
tag: timer_notification
- action: notify.mobile_app_someoneelses_iphone
data:
message: clear_notification
data:
tag: timer_notification
mode: single