diff --git a/custom_components/pyscript/eval.py b/custom_components/pyscript/eval.py index dea95cc..2d3eef6 100644 --- a/custom_components/pyscript/eval.py +++ b/custom_components/pyscript/eval.py @@ -70,6 +70,7 @@ "payload", "payload_obj", "qos", + "retain", "topic", "trigger_type", "trigger_time", diff --git a/custom_components/pyscript/mqtt.py b/custom_components/pyscript/mqtt.py index 25d72a1..8e15b3d 100644 --- a/custom_components/pyscript/mqtt.py +++ b/custom_components/pyscript/mqtt.py @@ -45,6 +45,7 @@ async def mqtt_message_handler(mqttmsg): "topic": mqttmsg.topic, "payload": mqttmsg.payload, "qos": mqttmsg.qos, + "retain": mqttmsg.retain, } try: diff --git a/docs/reference.rst b/docs/reference.rst index 7c7dd96..5f62226 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -778,13 +778,14 @@ An optional ``str_expr`` can be used to match the MQTT message data, and the tri if that expression evaluates to ``True`` or non-zero. This expression has available these variables: -- ``trigger_type`` is set to "mqtt" -- ``topic`` is set to the topic the message was received on +- ``trigger_type`` is set to "mqtt". +- ``topic`` is set to the topic the message was received on. - ``qos`` is set to the message QoS. -- ``payload`` is set to the string payload of the message +- ``payload`` is set to the string payload of the message. - ``payload_obj`` if the payload was valid JSON, this will be set to the native Python object representing that payload. A null message will not be converted. If payload_obj is a required function argument an exception will be thrown, use payload_obj=None. +- ``retain`` is set to the message retain flag. True if the message was retained, False otherwise. When the ``@mqtt_trigger`` occurs, those same variables are passed as keyword arguments to the function in case it needs them. Additional keyword parameters can be specified by setting the