I am new here, but been using home assistant for the last couple of months after migrating from OpenHAB. So far I think it is great, but am struggling with my most recent configuration, I wonder if anyone can shed some light on the correct way to progress. Just point me in the right direction, because i believe i might be barking up the wrong tree.
I have a service that pushes data to a webhook (brewfather). From this I have been successful in triggering an automation and passing the payload to that automation (just a notification)
This passes the raw payload JSON, just so i know i can get at it and the webhook is working.
The JSON contains the following data items:
id:
type:
time:
temp:
sg:
angle:
battery:
rssi:
What ideally want to be able to do is set up a bunch of sensors (or a entity) that I can use to replay this data onto the dashboards (and ultimately log in grafana).
I can’t find how to setup custom sensors or entities in home assistant so i can pass the JSON payload to set their values.
I have trawled through the docs and forums and it looks like templates are the way to go, but it seems that can only be used to map one sensor to another.
- alias: Capture Ispindel from Brewfather
trigger:
- platform: webhook
webhook_id: brewfather
action:
service: rest_command.update_webhook_sensor
data:
# Make sure the sensor id is unique. Can name it whatever you want really.
sensor_id: "sensor.{{trigger.json.id}}"
# Make the state whatever you want. Can be a value from the json even.
state: "{{'Available' if trigger.json else 'Unavailable'}}"
# Just store the entire json as individual attributes.
attributes_json: "{{ trigger.json }}"
There will most certainly be some tweaks required. Probably have to fix the rest_command payload template at the very least lol.
If there are multiple types, you could use that to map them to the right sensor type (binary_sensor, climate, etc). Assuming these were all valid types that were supported…you could do:
Actually, I think what you are suggesting is that i update the sensor through the restful API.
I think where I am failing is a can’t work out how to add a (blank) custom sensor to fill with data. Rather than a sensor from an integration. I assume you actually need a sensor to update through the API
I think i’m missing a fundamental piece of how this works
Nope, this will just create a sensor if the endpoint doesn’t exist.
Try it yourself. Open curl and post to /api/states/sensor.this_is_cool and give it a state. It will show up.
But do note, this sensor will disappear on all reboots until a new webhook trigger is received. In which case I would maybe create a template sensor that tracks this webhook sensor so you have something there on reboots.
This is where custom integrations get an advantage as they can store their info in a database to live beyond reboots.
This is exactly what I am attempting to do Mat! Have you had any success with this method? I started using the webhook trigger to set the value of an input number, but I think I like the idea of storing it in a sensor better.
I love using the iSpindel to track fermentation, such neat data to have!
I struggled massively with that and decided to change tack and use node-red to connect to the brewfather web hook and used home assistant extension to feed it into sensors.
Also worth noting that there is a brewfather addon for node-red which means you can pull details of your batches. I still have a couple of wrinkles to iron out but i’m getting there
Hey, that’s pretty cool - I didn’t even really consider checking there. It lead me to realise that Brewfather has an API that can be used to gather data about your brews etc. It looks like this is what the Node Red solution is doing. Having never used a REST API or been a much of a programmer, I thought I’d give it a crack - because I didn’t already had enough to do in life, right?
So using a REST sensor and checking the API for content is probably a comparatively straightforward way of doing this. If I make any headway, I’ll chuck it up on here.
I’m in the same boat, but don’t use brewfather! is there a way to get the ispindel http post to hit HA directly and populate the data in a sensor ? I currently use ubidots to view my data and send webhooks to HA to drive a smart plug connected to a brew pad to control temp. It would be far better to have the data in HA directly - graphing fermentation, battery, temp etc.
Is the RestAPI the way to go here, with a template sensor? I do not have experience of either, but assume its do-able ?
Nah, me either. Not sure how you would transform the payload into something useable. I might lean towards pointing it at node red or something as you may get a bit more flexibility.
Have you looked at using MQTT on the iSpindel? It basically sends out a simple message in JSON format that can be read by an MQTT broker. If you’re not already using it, you’d can set up an MQTT broker on HA and then use the MQTT sensors.
I used to use my iSpindel to connect to my HA like this and found it to be very well suited. Also, you can get a better polling rate than Brewfather allows (15mins), if you want higher resolution. I just wanted to use Brewfather to store the fermentation associated info with the batch, recipe etc. for convenience.
Thanks for the reply… I need to try with mqtt. I want sure of I needed something else running to take the mqtt messages and then send them to HA. But can the HA mqtt add on take the ispindel output directly? If so, it would be a nice clean option. I don’t use brewfather at all, and doing it this way would tidy up the automations I currently have via ubidots webhooks firing to HA
Hey mate,
No worries, and sorry about the delay here.
Yep, you can use the MQTT sensor directly with the iSpindel. You just need to make sure that you have configured the iSpindel to use the MQTT service when you set it up.
If you look at the relevant part of the source for the iSpindel, you can get an idea of what variables are output. You’ll also find it useful to get an MQTT client tool (such as MQTT X) on your PC whilst you are getting the whole thing sorted.
The code that I had used for this is here, but you’ll need to change the state topic to reflect the name you used for your iSpindels:
Thanks. I managed to get it working pretty quickly once I realised I’d been using the wrong IP in my MQTT setup!
I’m used to using ubidots to view the data, but the charts in HA are very basic compared (although I am looking at some HACS options). I may end up sticking with my current approach, and just using the webhooks from ubidots into HA.
Yeah, the default charts are pretty rubbish! I have been using mini-graph-cards and they’ve been pretty good. The apex charts look decent too, I will try to check them out in more detail sometime.