How do you use avalue from MQTT to set value

I’m trying to do an automation to receive a value in HA via MQTT and then send it to my car.
I can do a set value but not the actual value in the message.

- id: '1775574983400'
  alias: New automation
  description: ''
  triggers:
  - trigger: mqtt
    options:
      topic: skoda/chargeLimit
  conditions: []
  actions:
  - device_id: xxxxxxxxxxxxxxxxx
    domain: number
    entity_id: xxxxxxxxxxxxxxxxxxxxxxx
    type: set_value
    value: 50
  mode: single

How can i replace the 50 with the value in the mqtt message?

You will need to use a template that gets the value from the trigger variable. The precise template needed depends on the how the MQTT payload is structured. If you can share that, we can tell you what the template should be.

You can find the complete trigger variable object in the automation’s debug Trace, in the “Changed variables” tab near the bottom.

thank you, the payload of the mqtt message will just be a single value.

Eg. Topic; skoda/chargeLimit
Payload; 75

- id: '1775574983400'
  alias: New automation
  description: ''
  triggers:
  - trigger: mqtt
    options:
      topic: skoda/chargeLimit
  conditions: []
  actions:
  - device_id: xxxxxxxxxxxxxxxxx
    domain: number
    entity_id: xxxxxxxxxxxxxxxxxxxxxxx
    type: set_value
    value: "{{ trigger.payload | int }}"
  mode: single

FWIW, unless you need the ability to change the value from the frontend, it would likely be better to set this up as a standard MQTT sensor or a trigger-based template sensor.

Thank you very much, I’ll give that a go shortly.

It didn’t like the
value: “{{ trigger.payload | int }}”
and wouldn’t run so in the end I ended up setting up 4 automation’s for 70%, 80% 90% and 100%.

You’ll need to check the “Changed variables” tab toward the bottom of the automation Trace to see the actual structure of the payload being received, then we can help you figure out what changes need to be made.

Replace the Device Action with a number.set_value action. A Device Action does not support the use of templates.

- id: '1775574983400'
  alias: New automation
  description: ''
  triggers:
  - trigger: mqtt
    options:
      topic: skoda/chargeLimit
  conditions: []
  actions:
  - action: number.set_value
    target:
      entity_id: number.your_entity
    data:
      value: "{{ trigger.payload | int(0) }}"
  mode: single

Ensure you replace number.your_entity with your actual entity_id.

1 Like