Automation results in invalid JSON mqtt packet

I am trying to configure a input number (slider) for a home irrigation system using MQTT on a 4 channel Sonoff running Tasmota. An automation was created to forward the value of the slider to tasmota via MQTT.

When using the service mqtt.publish to publish the code below, it work’s!

{
  "topic": "cmnd/sonoff/Timer1",
  "payload_template": {"Time":"{{ states('input_number.slider1') }}"}
}

However, when the same service and data is inputed into an automation as an action, the Tasmota console shows “Invalid JSON” when the automation is triggered.

The following message was received while monitoring with an MQTT app on an iPhone.

cmnd/sonoff/Timer1
OrderedDict([(‘{time’, " 4.0}")])

where ‘4’ was the number set on the slider.

Here is my automation from automations.yaml

  • id: ‘1537040514181’
    alias: slider test
    trigger:
    • entity_id: input_number.slider1
      platform: state
      condition:
      action:
    • data:
      payload_template:
      Time: ‘{ states(’‘input_number.slider1’‘) }’
      topic: cmnd/sonoff/Timer1
      service: mqtt.publish

I’m wondering how this can be resolved to broadcast the same message as if it was entered from the service screen in home assistant.

I don’t use MQTT, but I would guess this would work:

  ...
  action:
    service: mqtt.publish
    data:
      topic: cmnd/sonoff/Timer1
      payload_template: {"Time":"{{ states('input_number.slider1') }}"}

or if you prefer:

  ...
  action:
    service: mqtt.publish
    data:
      topic: cmnd/sonoff/Timer1
      payload_template:
        Time: "{{ states('input_number.slider1') }}"

Thanks for the help, and sorry for the late response. Unfortunately, I tried both, and neither seemed to work.