Format value that Shutter Card passed to MQTT

Hi
Im using AMPIO as a house automation. It uses wierd raw MQTT topic to control % of shutter closing.
eg: 0001010065
000101 - this is id number of shutter on that device
00 i its a HEX value from 0 to 100
65 - not usable in my instalation

So I need to change value that shutter-card passed to position_topic from like:
67 to 0001014365
How can I do that?

I’d integrate it as a MQTT Cover, then translate it in set_position_template (docs) and position_template (docs).

e.g.:

# Of course, change the topics and everything else you might need,
# see the MQTT cover docs
cover:
  - platform: mqtt
    name: "MQTT Cover"
    command_topic: "home-assistant/cover/set"
    position_topic: "home-assistant/cover/position"
    availability:
      - topic: "home-assistant/cover/availability"
    set_position_topic: "home-assistant/cover/set_position"
    qos: 0
    retain: true
# Convert position to HEX inserted in the string
    set_position_template: >-
      000101{{ "%0x" | format( position | int ) }}65
# Extract Substring from 000101 00 65 (only char 6-8)
    position_template: >-
      {{ value[6:8] }}
1 Like

Thanks a lot, it works lika a charm :slight_smile:

1 Like