I am attempting to trigger an automation on an MQTT message which happens to contain a JSON-formatted payload.
My goal is to trigger on a specific JSON string being sent on a topic. MQTT triggers allow you to define the topic, and optionally, the payload.
-
If I create an automation which listens on a topic, set the expected payload to a valid JSON string, and then publish a message which matches the expected payload, the automation does not trigger.
-
If I create an automation which listens on a topic, set the expected payload to string which is not a valid JSON object, and then publish a message which matches the expected payload, the automation will trigger.
I have created a blueprint which demonstrates the situation which you can find here (this only works in the March beta to make it easier to demonstrate. Replace all templates with string literals and the behavior persists).
What appears to be happening is that Home Assistant is parsing the JSON, but doesn’t allow you to use the parsed version in the trigger, nor does it seem to allow you to use the non-parsed version either.
A common solution here would be to catch everything published on that topic, and then use a condition later, but that’s a problem because this is being used in the context of a blueprint with several triggers which each have their own path selected via choose
in the main automation. So, conditions are no good because they will break all of the other functions of the blueprint. The approach being used today is to catch everything published, then use choose
to filter it out later, but that creates a huge number of pointless automation triggers and is negatively impacting performance.