MQTT dynamic topic publish2

Hi!
I have multiple blinds connected to custom (esp32) device to tilt and open/close.

I’m using MQTT to communicate with the esp32 and everything work fine to get/set data (with node-red)!

Now I want to set limits for the motors. I’ve created helpers and add it to lovelace in sort of button.

I’ve connect the “buttons” to call service and select mqtt.publish .

At this time, i’m able to run a motor completely!
via custom topic : blinds/BLIND-001/state

but I want to run the orhers motors via other topic
(blinds/BLIND-xxx/state)

thats why i’ve made the first input (slider) … to switch the motor that I want to control.

I’ve try with this yaml (i put only 1 button here)

type: button
icon: 'mdi:blinds'
tap_action:
action: call-service
service: mqtt.publish
service_data:
    payload: downTilt
    topic: 'blinds/BLIND-00{{states("input_number.blindselector"}}/state'
entity: input_boolean.tilt_down

the payload is send to topic:
blinds/BLIND-00{{states(“input_number.blindselector”}}/state

… in other words… the {{ … }} is treated litteraly and not compute the state of my input_number.blindselector

​my questions is:
How can I concatenate string with variable in the current yaml?

thanks in advance (and sorry for my english)

The call-service action does not accept templates. That means the template you created in topic is unsupported.

Create a script to tilt a blind and then set call-service to call the script.

tap_action:
  action: call-service
  service: script.tilt_blind

The script can contain most of your existing code:

tilt_blind:
  alias: Tilt Blind
  sequence:
  - service: mqtt.publish
    data:
      payload: downTilt
      topic: 'blinds/BLIND-00{{states("input_number.blindselector"}}/state'

whoa!!! :dizzy_face: it’s working!!! :hugs:
Big thanks!

Discover Script made my day!

Thank you very much!

1 Like