Publish Measurements with MQTT - Payload issue

Hi,

i upgraded to mycodo 8.13.9. I’m receiving values from my sensor and try to publish them via MQTT (worked with an earlier version):

# Example code for learning how to use a Conditional. See the manual for more information.

#self.logger.info("This INFO log entry will appear in the Daemon Log")
#self.logger.error("This ERROR log entry will appear in the Daemon Log")

if not hasattr(self, "loop_count"):  # Initialize objects saved across executions
    self.loop_count = 1
else:
    self.loop_count += 1

temperature = self.condition("{4cb2d3cd}") 
humidity = self.condition("{6c1f97c1}")
dewpoint = self.condition("{d53bc3be}")
vaporpressuredeficit = self.condition("{d526cfb5}")

temperature = "{:.2f}".format(temperature)
humidity = "{:.2f}".format(humidity)
dewpoint = "{:.2f}".format(dewpoint)
vaporpressuredeficit = "{:.2f}".format(vaporpressuredeficit)

self.logger.debug("Temperature published via MQTT {val}".format(val=temperature ))
self.logger.debug("Humidity published via MQTT {val}".format(val=humidity ))
self.logger.debug("Dewpoint published via MQTT {val}".format(val=dewpoint ))
self.logger.debug("Vapor Pressure Deficit published via MQTT {val}".format(val=vaporpressuredeficit ))

self.run_action("{b3974885}", temperature)
self.run_action("{c37dc071}", humidity)
self.run_action("{0ce5a183}", dewpoint)
self.run_action("{44ba2cb9}", vaporpressuredeficit)

now i get an bunch of unmatched format errors and “cannot publish without payload”

022-05-10 22:56:34,090 - ERROR - mycodo.function_action.mqtt_publish_b3974885 -  Error: Cannot publish to MQTT server without a payload.
2022-05-10 22:56:34,121 - ERROR - mycodo.daemon - Could not trigger Conditional Actions: unsupported operand type(s) for +=: 'NoneType' and 'str'
Traceback (most recent call last):
  File "/var/mycodo-root/mycodo/mycodo_daemon.py", line 977, in trigger_action
    return trigger_action(
  File "/var/mycodo-root/mycodo/utils/actions.py", line 339, in trigger_action
    message += "\n[Action {id}, {name}]:".format(
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
2022-05-10 22:56:34,154 - ERROR - mycodo.daemon - Could not trigger Conditional Actions: unsupported operand type(s) for +=: 'NoneType' and 'str'
Traceback (most recent call last):
  File "/var/mycodo-root/mycodo/mycodo_daemon.py", line 977, in trigger_action
    return trigger_action(
  File "/var/mycodo-root/mycodo/utils/actions.py", line 339, in trigger_action
    message += "\n[Action {id}, {name}]:".format(
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
2022-05-10 22:56:34,187 - ERROR - mycodo.daemon - Could not trigger Conditional Actions: unsupported operand type(s) for +=: 'NoneType' and 'str'
Traceback (most recent call last):
  File "/var/mycodo-root/mycodo/mycodo_daemon.py", line 977, in trigger_action
    return trigger_action(
  File "/var/mycodo-root/mycodo/utils/actions.py", line 339, in trigger_action
    message += "\n[Action {id}, {name}]:".format(
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

I tried publishing an static value, that worked. I did set the payload types to “Float / Decimal” because they were empty / “choose one”.

Any ideas what the issue is?

Thanks!

1 Like

Hi Markus. Inputs can now have their own Actions added to them, which includes an MQTT Publish Action, so I’d suggest using that from the Input Configuration, rather than a function to publish measurements.

However, what you’re observing is a bug, and it’s resulting from not passing a string to the message parameter of the run_action() function. I just pushed a fix for cases where no message is passed:

1 Like

Thank you very much!
I switched to the MQTT Publish Action directly at the Input level and it works great :slight_smile:

Thank you
Markus

1 Like