Configure webhook sensors to receive json-data from script


I have an SDM120 modbus energy meter connected to a Raspberry Pi with Domoticz.
There is a scheduled script that that reads the modbus and sorting out values to send them to Domoticz.
That works great - but I want it to send the data to HA at same time …

This is how the script send data to Domoticz:

curl -s {$SERVER"/json.htm?type=command&param=addlogmessage&message="SDM120Update_FAILED!!!""}  #send loginfo to domoticz
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="864"&nvalue=0&svalue="$TOTAL""}  #send total to Domoticz (energy "kWh")
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="886"&nvalue=0&svalue="$POWER";"$TOTAL""}  #send POWER/TOTAL to Domoticz to calculate daily kWh used
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="859"&nvalue=0&svalue="$VOLTAGE""}  #send voltage to Domoticz (voltage "V")
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="869"&nvalue=0&svalue="$POWER""}  #send power to Domoticz (power "W")
curl -s {$SERVER"/json.htm?type=command&param=udevice&idx="870"&nvalue=0&svalue="$AMPERE""}  #send ampere to Domoticz (current "A")

I want to send the same data to HA, and thinking like this:

curl -X POST -H "%auth%" -H "Content-Type: application/json" -d "{"voltage": "$VOLTAGE", "power": "$POWER", "energy": "$TOTAL", "current": "$AMPERE"}" http://homeassistant.local:8123/api/webhook/SDM120

But I am not sure how to set it up in HA…

I have searched alot and found bits and pieces, I guess that I need an “Automation” to use webhooks, but I have no idea how to configure that with sensors - and how to use unit_of_measurement, device_class and data_type.

I have seen value_template, but I am very new to HA (abt. 2 weeks) and have not really grasped the concept of templates and when to use them or not.
Is is something like this?

     - name: "SDM120_V"
        state: "{{ trigger.json.voltage }}"
        unit_of_measurement: V
        data_type: float

Can someone point me in the right direction?

Best regards

1 Like

That is pretty much it yes.
Some notes however, webhooks should really have a rather long obscure webhook, rather than simple text, because especially if you expose Home Assistant to the outside world, either with a simple port forward, or via NabuCasa (Home Assistant Cloud). ANYONE can post data to your webhook URL, without any authentication.

Additionally, there isn’t a lot of point in posting all that JSON, because each sensor will need it’s own webhook, and you will need need to post to each webhook, just like you do currently with the domoticz idx’s (I’m a Domoticz convert too, I remember Domoticz very well).

FYI I use Online UUID Generator Tool to generate my webhook IDs, I remove the hyphens, and generate 2 UUIDs and stick them together to create a completely unguessable webhook.