I’m trying to get a system working using MQTT auto discovery. The device being controlled is kind of annoying. I can send commands to it, and wait for a response, but I’m unable to monitor the device itself (making an MQTT switch inappropriate.)
My “solution” is to use an MQTT button to send commands to the device (which works) and have the device use MQTT events (MQTT Event - Home Assistant) to send the response back (which is either “success” or “failure.”
My MQTT autodiscovery config to the response event is similar to this:
{
"name": "command_result",
"device": {
// stuff deleted
},
// availability stuff here
"retain": false,
"state_topic": "homeassistant/event/some-identifier/command_result/state",
"event_types": [
"success",
"failure"
]
}
This appears to work. My device is absolutely sending an “event_type”:“failure” payload to the proper topic whenever the command fails. However, I’m finding that I can’t use an automation to handle “failure” responses. As a simple case, here’s an automation that should give me a notification if the command ever fails:
alias: TESTING
description: ""
trigger:
- platform: state
entity_id:
- event.some-identifiercommand_result
attribute: event_type
to: failure
condition: []
action:
- service: notify.notify
data:
message: Failed to cancel starting the vehicle
mode: single
This only works once. If the command fails multiple times, the MQTT event never fires again. I can see why: The payload of the topic never changes… it’s always “failure”. So, I guess I need some other kind of automation action, but what?
I believe that my usage of the MQTT event is correct, based on the example in the docs. That example uses a doorbell and has “press” and “hold” event types. Obviously, if someone presses it (without holding), it could trigger an automation. However, if it’s pressed a second time, the event type would still be seen by HA as “press” and therefore no change would be detected!
Please help