Hello,
First of all i’m a beginner of MQTT and HS, which means I am still searching a lot on the forum and have based on an existing automation a working script. But get stuck on a snall part of it.
I’m trying to split a MQTT payload with the next code:
- alias: split mqtt
trigger:
platform: mqtt
topic: /interface/pvinverter/Action
action:
- variables:
data: "{{ trigger.payload[5:-1].split(',') }}"
item: ['action', 'vp1', 'fac', 'ip1']
- repeat:
count: '{{ item | length }}'
sequence:
- service: mqtt.publish
data:
topic: '/interface/pvinverter/Action/{{item[repeat.index-1]}}'
payload: '{{data[repeat.index-1]}}'
what works, however the preset label (if I may call it that) is not needed because it’s already in the payload so i want to use that label.
Now I will get splited info like: vp1 = “vp1”,“3831”
So if I receive this value from the MQTT the sensor give me a “vp1”,“3831” input.
I figure out that the item: [‘action’, ‘vp1’, ‘fac’, ‘ip1’] can be removed but want to use the orginal label text as item.
I have for example the next source:
{"Action":"UpdateInvData","vp1":"3831","fac":"5000","ip1":"2"}
How can i do that?