[SOLVED] Error when using Jinja in action payload

I want to set up an automation that sets the fan speed of an air purifier depending on the pm2.5 level. I’m getting an error “Message malformed: template value should be a string for dictionary value @ data[‘actions’][0][‘data’]”. I tried both: creating this through the UI and directly in the yaml file.

What am I doing wrong?

alias: Levoit adaptive fan control
description: ""
triggers:
  - trigger: time_pattern
    minutes: /5
conditions: []
actions:
  - action: fan.turn_on
    metadata: {}
    data:
      percentage: >
        {% let pm = states('fan.levoit_300s') | int %} {% if pm < 6 %}
          33
        {% elif pm > 15 %}
          100
        {% else %}
          67
        {% endif %}
    target:
      device_id: xxx
mode: single

Change let to set

:man_facepalming: Thank you, that’s embarrassing…

1 Like

No worries. Sometimes it just takes another pair of eyes to spot the problem.