Using MQTT to set a value from an Automation

I want to be able to set the power output of a heater from an automation script but I cannot work out how to do this. I have an mqtt.yaml file with this in it:-

  number:
  - unique_id: unit1
    name: "MQTT unit 1"
    state_topic: "divert/unit1_maxpower"
    command_topic: "divert/unit1_maxpower/set"
    min: 0
    max: 3000
    qos: 0
    retain: true    

This allows me to control the heater output power manually from the Dashboard but as it is listed an entity rather than a device I cannot add an action to an automation to set a particular output power on a trigger event. How to I get my unit to be listed as a “device”?
Am I wrong to be using “number:” , do I have the wrong parameters set or is this not possible using yaml and I need to delve into scripting?

Use the Call Service action, and the number.set_value service:

Brilliant. Thanks for the response it works a treat, I would never have guessed that was the way to do it.

1 Like