MQTT automation formatting

I’m trying to wrap my head around formatting an automation for controlling my pool over an RS485 interface:

Another user here has graciously shared how they got it working on their similar system, however I’m getting errors when trying to use an MQTT publish automation to set the pool heater.

Here’s what my automation looks like:

- alias: convert_setpoint
  trigger:
    platform: mqtt
    topic: pool/setPoint
  action:
    service: mqtt.publish
    data_template:
      topic: easytouch2-8/state/body/setPoint
      payload: '{  "id": 1, "setPoint": {{trigger.payload | int }}   }'

And here’s the log error I’ve been seeing whenever I use the pool heater’s climate control card to change the temperature:

TypeError: payload must be a string, bytearray, int, float or None.
2020-11-15 08:07:12 ERROR (MainThread) [homeassistant.components.automation.convert_setpoint] While executing automation automation.convert_setpoint
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 426, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1010, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 245, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 253, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 460, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1448, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1483, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 581, in async_publish_service
    await hass.data[DATA_MQTT].async_publish(msg_topic, payload, qos, retain)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 782, in async_publish
    msg_info = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1259, in publish
    raise TypeError(
TypeError: payload must be a string, bytearray, int, float or None.

I suspect there’s something off with the way I’m formatting that last very last line in my autiomation.yaml?
Everything before that seems to work based on the MQTT messages that I’m seeing.

Not sure but probably the whole payload need to be a string. You have now 2 strings and 2 ints. I would try :

'{  "id": "1", "setPoint": {{trigger.payload }}   }'

Are you using version 0.117?

Have you changed the legacy_templates option from its default value of true to false?

Thank you Eddy and Taras for the suggestions.

Yep! I’m in 0.117. I’ve now set that legacy_templates option to false (added the following lines to my configuration.yaml):

homeassistant:
  legacy_templates: false

which seemed promising based on what I’m trying to decipher from the release notes… but still getting the same exact error when I execute my automation.

I’ve also tried the suggestion of removing | int and adjusting the quotes in my payload:

      payload: '{  "id": 1, "setPoint": {{trigger.payload }}   }'

but that too gives the exact same “TypeError: payload must be a string, bytearray, int, float or None. …”

Appreciate the suggestions and I’m happy to try any more you might have. Just to make sure I’m understanding, the way I read that error message suggests there must be something either in how my automation payload is formatted, or else in how that payload is subsequently being parsed by 0.117?

Just a quick aside… apologies for not noticing this earlier… a couple lines up from where my setpoint converter automation fails is this:

2020-11-17 06:25:49 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to pool/setPoint, mid: 28
2020-11-17 06:25:56 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on pool/setPoint: '99.0', mid: 29
2020-11-17 06:25:56 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on pool/setPoint: b'99.0'

My MQTT received messages in my log are prefixed with a ‘b’, even though they aren’t transmitted with one. Is that normal behavior?