All,
I am struggling extracting the data I need from MQTT.
I have a sensor, which receives the mqtt payload:
- sensor:
state_topic: "nuki/Lock_ID/lockActionEvent"
name: "Letzter Haustürschloss Benutzer (MQTT roh)"
icon: mdi:raw
unique_id: sensor_letzter_hausturschloss_benutzer_mqtt_raw
The result string is e.g.
3,0,111111,1234,2
The last digit is the user ID which I need to extract.
I did this for testing (successful for a single result check) within the template sensor above with (where 1234 sometimes changes):
value_template: '{% if value|regex_search(''3,0,111111,\\d{4},2'', ignorecase=FALSE)%}User{% endif %}"
Because I prefer having the logic in the automation (and combining of if
for multiple cases) I am trying to translate the MQTT payload into users with a template like and set a dropdown (input_select
) accordingly:
condition: template
value_template: >-
{{ regex_search('3,0,111111,\\d{4},2') in states('sensor.letzter_hausturschloss_benutzer_mqtt_roh') }
but I get:
Message malformed: invalid template (TemplateSyntaxError: expected token ',', got 'integer') for dictionary value @ data['action'][0]['if'][0]['value_template']
I guess this means that HA transforms the MQTT string into an integer (even though I don’t know how with all these commas).
I also would prefer to use a text_sensor or something, but that’s not possible I guess.
So how do I check the raw string for specific sub-strings to set the input_select accordingly?
Thanks in advance.
NCO
EDIT:
I just found the mqtt text
option and will try this.
Any help in the meantime would still be appreciated
EDIT II:
That’s not working either