Skip to content

Commit ef0ae1c

Browse files
MQTT Error Video
1 parent 75a9a80 commit ef0ae1c

File tree

6 files changed

+202
-0
lines changed

6 files changed

+202
-0
lines changed

2022-09-MQTTErrors/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div align="center">
2+
<img src="../images/slacker_labs.png">
3+
<h1>MQTT Errors</h1>
4+
<br>
5+
6+
[![Watch the video](../images/videos/tn-2022-MQTTErrors.png)](https://youtu.be/SKvuW5mUVJU)
7+
8+
</div>
9+
10+
11+
<h2>Files You Need</h2>
12+
13+
**configuration.yaml**
14+
15+
Contains link to mqtt.yaml file, or mqtt: definitions.
16+
17+
**mqtt.yaml**
18+
19+
Example of the mqtt.yaml file.
20+
21+
22+
23+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
# Configure a default setup of Home Assistant (frontend, api, etc)
4+
default_config:
5+
6+
# Only uncomment this if you want to use the package directory.
7+
# Otherwise copy the sensor section below and the scripts in tje sceript directory.
8+
#http:
9+
#packages: !include_dir_named packages # needed if you are going to use packages
10+
11+
mqtt: !include mqtt.yaml
12+
13+
# Or just define them in this file like:
14+
15+
# mqtt:
16+
# sensor:
17+
# - name: "Family Status"
18+
# state_topic: "house/family/status"
19+
# payload_available: "online"
20+
# payload_not_available: "offline"
21+
# - name: "Family Arrived"
22+
# state_topic: "house/family/arrived"
23+
# payload_available: "online"
24+
# payload_not_available: "offline"
25+
# - name: "Jeff Last Known Location"
26+
# state_topic: "house/jeff/last_known_location"
27+
# payload_available: "online"
28+
# payload_not_available: "offline"
29+
# - name: "Kat Last Known Location"
30+
# state_topic: "house/kat/last_known_location"
31+
# payload_available: "online"
32+
# payload_not_available: "offline"
33+

2022-09-MQTTErrors/mqtt.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sensor:
2+
- name: "Family Status"
3+
state_topic: "house/family/status"
4+
payload_available: "online"
5+
payload_not_available: "offline"
6+
- name: "Family Arrived"
7+
state_topic: "house/family/arrived"
8+
payload_available: "online"
9+
payload_not_available: "offline"
10+
- name: "Jeff Last Known Location"
11+
state_topic: "house/jeff/last_known_location"
12+
payload_available: "online"
13+
payload_not_available: "offline"
14+
- name: "Kat Last Known Location"
15+
state_topic: "house/kat/last_known_location"
16+
payload_available: "online"
17+
payload_not_available: "offline"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+

2022-09-MQTTErrors/secrets.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Use this file to store secrets like usernames and passwords.
2+
# Learn more at https://www.home-assistant.io/docs/configuration/secrets/
3+
some_password: welcome
4+
5+
# Update these if you are going to use Amazon Polly config in
6+
# the configuration.yaml
7+
aws_key: fbvekjbvwblv
8+
aws_secret: nfegvwvlwbljew
318 KB
Loading

0 commit comments

Comments
 (0)