Automation based on part of MQTT payload

Manged to split the string into segments using this example:

Which gives me subtopics that I can monitor for the specific device. Not everything reports properly but I get out what I need so I’m happy.

My current code:
alias: RFLINK32 String Split
description: ‘’
trigger:
platform: mqtt
topic: /ESP00/msg
action:

  • variables:
    data: ‘{{ trigger.payload[5:-1].split(’‘;’‘) }}’
    item:
    • counter1
    • DeviceType
    • DeviceID
    • Switch
    • State
    • Unknown
  • repeat:
    count: ‘{{ item | length }}’
    sequence:
    • service: mqtt.publish
      data:
      topic: /ESP00/msg/{{item[repeat.index-1]}}
      payload: ‘{{data[repeat.index-1]}}’