|
| 1 | + |
| 2 | + |
| 3 | +# Sensors to grab data from MQTT for use in scripts |
| 4 | +sensor: |
| 5 | + - platform: mqtt |
| 6 | + name: "Jarvis Last Msg" |
| 7 | + state_topic: "house/polly/lastmsg" |
| 8 | + - platform: mqtt |
| 9 | + name: "Jarvis Last Location" |
| 10 | + state_topic: "house/polly/lastloc" |
| 11 | + - platform: mqtt |
| 12 | + name: "Jarvis Last Msg Time" |
| 13 | + state_topic: "house/polly/msgtime" |
| 14 | + |
| 15 | +# For those of you Wathcing this after the 2022.6 release use this: |
| 16 | +# mqtt: |
| 17 | +# sensor: |
| 18 | +# - name: "Jarvis Last Msg" |
| 19 | +# state_topic: "house/polly/lastmsg" |
| 20 | +# - name: "Jarvis Last Location" |
| 21 | +# state_topic: "house/polly/lastloc" |
| 22 | +# - name: "Jarvis Last Msg Time" |
| 23 | +# state_topic: "house/polly/msgtime" |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +# # To call the speech engine script below use the following as a guide: |
| 30 | + |
| 31 | +# - service: script.speech_engine_simplified |
| 32 | +# data: |
| 33 | +# who: '{{ states(''sensor.room_audio'') }}' |
| 34 | +# message: > |
| 35 | +# At {{ states('sensor.jarvis_last_msg_time') }} in the {{ states('sensor.jarvis_last_location') }} I said. {{ states('sensor.jarvis_last_msg') }} |
| 36 | +# msg_summary: "recall" |
| 37 | + |
| 38 | +script: |
| 39 | + # A simplified Speech Engine that for your text to speech notifications. |
| 40 | + speech_engine_simplified: |
| 41 | + sequence: |
| 42 | + # Any conditions you want to include. |
| 43 | + |
| 44 | + # - condition: state |
| 45 | + # entity_id: input_boolean.audible_notifications |
| 46 | + # state: 'on' |
| 47 | + |
| 48 | + # Call your TTS Service |
| 49 | + - service: tts.amazon_polly_say |
| 50 | + data_template: |
| 51 | + entity_id: >- |
| 52 | + {{ who }} |
| 53 | + message: >- |
| 54 | + <speak> |
| 55 | + <break time="1s"/> |
| 56 | + {{ message }} |
| 57 | + </speak> |
| 58 | + cache: true |
| 59 | + |
| 60 | + # Save your message for recall |
| 61 | + - service: mqtt.publish |
| 62 | + data_template: |
| 63 | + topic: 'house/polly/lastmsg' |
| 64 | + payload: > |
| 65 | + {% if msg_summary == 'recall' %} |
| 66 | + {% set msg_summary = '{{states(''sensor.jarvis_last_msg'')}}' %} |
| 67 | + {% else %} |
| 68 | + {% if msg_summary %} |
| 69 | + {% set message = msg_summary %} |
| 70 | + {% endif %} |
| 71 | + {%- macro cleanup(data) -%} |
| 72 | + {%- for item in data.split("\n") if item | trim != "" -%} |
| 73 | + {{ item | trim }} {% endfor -%} |
| 74 | + {%- endmacro -%} |
| 75 | + {{- cleanup( message | striptags | truncate(220) ) -}} |
| 76 | + {% endif %} |
| 77 | +
|
| 78 | + # Save time of last message |
| 79 | + - service: mqtt.publish |
| 80 | + data_template: |
| 81 | + topic: 'house/polly/msgtime' |
| 82 | + payload: > |
| 83 | + {{ now().strftime("%-I") }}:{{ now().strftime("%M") }} {{ now().strftime("%p") }} |
| 84 | + retain: true |
| 85 | + |
| 86 | + # Save location |
| 87 | + - service: mqtt.publish |
| 88 | + data_template: |
| 89 | + topic: 'house/polly/lastloc' |
| 90 | + payload: '{{ who }}' |
| 91 | + retain: true |
| 92 | + |
| 93 | + # Script for playing the last message. |
| 94 | + # You can call this from a routing on the Google Home or Amazon Echo |
| 95 | + # Or from an automation tiggered by a button. |
| 96 | + play_last_message: |
| 97 | + sequence: |
| 98 | + - service: script.speech_engine_simplified |
| 99 | + data: |
| 100 | + who: '{{ states(''sensor.room_audio'') }}' |
| 101 | + message: > |
| 102 | + At {{ states('sensor.jarvis_last_msg_time') }} |
| 103 | + in the {{ states('sensor.jarvis_last_location') }} |
| 104 | + I said. {{ states('sensor.jarvis_last_msg') }} |
| 105 | + msg_summary: "recall" |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
0 commit comments