I’m trying to create a input_boolenan switch that would send an MQTT message to a Zanzito device, and I want the switches to automatically turn off after Zanzito receives the message.
Here is the automation and script that sends a notification, say, alarm/play, or alarm/stop to a device based on what I select from an input field (https://goo.gl/mYr6RN).
input_select:
zan_message_type:
name: Zanzito Message Type
options:
- notification
- say
- alarm/play
- alarm/stop
zan_device_name:
name: Zanzito Device Name
options:
- me
- John
- Taylor
input_text:
zan_message_text:
name: Zanzito Message Text
input_boolean:
zanzito_send_message:
name: Zanzito Send Message
initial: off
icon: mdi:alarm-multiple
automation:
- alias: Zanzito message switch goes on
trigger:
platform: state
entity_id: input_boolean.zanzito_send_message
from: 'off'
to: 'on'
action:
- service: script.zanzito_send_message
data_template:
dest_id: '{{ states.input_select.zan_device_name.state }}'
message_type: '{{ states.input_select.zan_message_type.state }}'
message: '{{ states.input_text.zan_message_text.state }}'
script:
zanzito_send_message:
alias: Zanzito Send Message
sequence:
service: mqtt.publish
data_template:
topic: 'zanzito/{{ dest_id }}/{{message_type}}'
payload: '{{ message }}'
qos: 1
retain: 0
It’s not a big deal having to change the input_boolean back to off after sending the message, but it would be nice to know if it was even received (and then turn off the switch itself if it was).
I’m not very familiar with mqtt and the qos parameter, but qos 1 supposedly sends back feedback that the message was received, but I don’t know where that feedback is recorded and how to use it so that I can setup a second workflow to turn off the input_boolean that triggered the message in the first place?
I know that there is a way to create a sensor with “payload_on: “ack”” to know if an alarm was turned off. This is nice, but I just want to know if Zanzito got the message in the first place. Any advice?