Pulling data from API and using for automating - technical best way to do that?

So I am pulling data from Tibber API for day ahead prices. There are several topics about how to do that. My question is not about how. But what would be best. I want to automate a couple of things, like figuring out what the best hours are to heat the water in the tank of our heat pump. So the actual process broadly speaking looks like this:

  1. Pulling API data
  2. Logic to decide what’s best (I think Node-Red is indispensable for this? Or maybe a custom Python script but standard automations are too limited I think)
  3. Create schedule for actions (heating water, changing working mode of inverter etc)
  4. Executing actions
  5. Showing status and / or strategy for coming 24/36 hours on dashboard.

Starting with one, my main question is what would technically be best to do? On one hand, one could say a sensor of the rest-request type might be best as that is standard Home Assistant. Using an automation to run it daily instead of based on scan_interval. On the other hand, if I were to use Node Red, getting the data from HA sensor to Node Red would be an extra step, so Node Red might be the best option? Same for Python, if I were to use Python for the logic wouldn’t it be best to request data through the Python script and make it send the data to HA as a sensor?

Let me know what you guys think, I like to do things in a technically neat way.

Nobody with an opinion or advice?

‘Best’ is very subjective. We all have opinions. Advice is free (to a point). This is just my thoughts…

I vote for Node-RED for doing most of the work.

Node-RED is fast and easy to prototype, and you can set up API calls quickly and easily. NR was designed for event-based IOT work such as this.

Node-RED is great for data processing, and JSONata is excellent at manipulating the complex JSON stuctures you get back from an API call.
Node-RED can manage short-term data capture. Using context memory, and even setting this to file-base context so as to recover from restarts.

Node-RED can connect to HA very easily using the HA WebSocket nodes. To execute an action in NR using the ‘Action’ node is no different to doing it in HA.

Node-RED is independent of HA, so it is possible to run it anywhere, and avoid problems with HA upgrades.

Node-RED has its own dashboard and button-interaction, so the entire setup can be tested / duplicated for redundancy as required. HA and NR dashboards are different, and whilst NR is easy to build an interactive ‘system’, HA is probably richer, and certainly easier to see and use on a mobile phone.

Home Assistant is probably better for simple automations, for capturing state values and showing history.

The end result in Home Assistant
Octopus Agile - day ahead pricing

with best-price schedules

And everything is done in Node-RED using JSONata.

1 Like