I’m trying to setup a webhook that sends a string of data wrapped in json - the automation looks like its getting called via the Logbook entry:
- I’m not assigning the values correctly into a sensor
- it’s only processing the first parse i.e. [20] and skipping [6a]
Data:
‘{“payload”: “[20]15.50[6a]18.00[5e]15.31[26]20.87”}’
When I send the data I see this in the Logbook:
Executed: January 23, 2024 at 9:09:11 PM
Result:
params:
domain: template
service: create
service_data:
template: 59.9
target:
entity_id:
- sensor.temp20
running_script: false
Here’s my yaml:
template:
- sensor:
- name: Temp 20
unique_id: temp20
entity_id: temp20
unit_of_measurement: "°F"
- sensor:
- name: Temp 6a
unique_id: temp6a
entity_id: temp6a
unit_of_measurement: "°F"
automation:
- id: parse_and_convert_webhook_payload
alias: "Parse and Convert Webhook Payload"
trigger:
platform: webhook
webhook_id: your_webhook_id # Replace with your actual webhook ID
action:
- service: template.create
data:
template: >-
{% if trigger.json.payload | regex_search('\[20\]([\d.]+)') %}
{{ (trigger.json.payload | regex_findall_index('\[20\]([\d.]+)') | float * 9/5 + 32) | round(2) }}
{% endif %}
entity_id: sensor.temp20
- service: template.create
data:
template: >-
{% if trigger.json.payload | regex_search('\[6a\]([\d.]+)') %}
{{ (trigger.json.payload | regex_findall_index('\[6a\]([\d.]+)') | float * 9/5 + 32) | round(2) }}
{% endif %}
entity_id: sensor.temp6a