Node Red JSON to Automation

I have successfully imported data from Brewfather into Node Red (no integration exists in Home Assistant). I am using this as a brewery fermentation controller, so I would like to turn the 3 steps below into an automation that changes a climate temp controller.

I’m stuck on how this data can get from Node Red to Home Assistant and into an automation… just at a loss of even the basic theoretical steps I would need to take. Once I have an idea of the framework, I can fumble my way through it!

The data is in Node Red as below:

{
  "_id": "redacted",
  "name": "Batch",
  "batchNo": 39,
  "status": "Fermenting",
  "brewer": "Name",
  "brewDate": 1663916400000,
  "recipe": {
    "name": "Fruit Bazooka",
    "fermentation": {
      "steps": [
        {
          "stepTemp": 17.777778,
          "actualTime": 1664089200000,
          "ramp": null,
          "stepTime": 11,
          "displayStepTemp": 64,
          "type": "Primary",
          "pressure": null,
          "displayPressure": null
        },
        {
          "displayStepTemp": 50,
          "actualTime": 1665039600000,
          "ramp": null,
          "stepTime": 3,
          "pressure": null,
          "stepTemp": 10,
          "displayPressure": null,
          "type": "Primary",
          "name": "Dry Hop"
        },
        {
          "name": "Cold Crash",
          "displayPressure": null,
          "pressure": null,
          "actualTime": 1665298800000,
          "ramp": null,
          "displayStepTemp": 35,
          "stepTime": 2,
          "type": "Primary",
          "stepTemp": 1.666667
        }
      ]
    }
  }
}

make a sensor node and set the data as states and attributes

1 Like

Was typing exactly what @WallyR did…

When you setup the sensor node you can add as many attributes as you want. I find it easiest just to set them all to flow variables (look up context, nodered if you need to learn about flow variables) and then as long as I have allow override set, then anytime I update a flow variabnle in any given flow - the sensor updates. For example, this sensor for a ‘room’ I’m working on:

.

It holds occupancy status and various flags, so I know what’s going on in that room.

which I use extensively in this card I’m building for Lovelace:
image

1 Like

Is there a way to have a variable number of attributes? So for the example I posted, I have three steps where the temp changes. Some recipes may only have one, some may have 10!

If not, I can figure out a way to hard code it, but it would be nice to have the flexibility.

[{"id":"25ef1c9c74581477","type":"ha-api","z":"be03f9025a1f137a","name":"sensor","server":"541ade28.b4a62","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":875,"y":750,"wires":[[]]},{"id":"06ac8e03a8a85876","type":"function","z":"be03f9025a1f137a","name":"make final payload","func":"msg.entity_id = `switch.test_entity2`;\n\nmsg.payload = {\n    data: {\n        state: 'On',\n        attributes: {\n            'name': 'test_entity2',\n            'attribute1': 'attribute_1',\n            'attribute2': 'attribute_2',\n            'attribute3': 'attribute_3',\n            'attribute4': 'attribute_4',\n            friendly_name: 'Test Entity 2',\n            icon: 'mdi:pulse'\n        }\n    }\n};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":705,"y":750,"wires":[["25ef1c9c74581477"]]},{"id":"39963ed0628d85b4","type":"inject","z":"be03f9025a1f137a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":525,"y":750,"wires":[["06ac8e03a8a85876"]]},{"id":"541ade28.b4a62","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

This seems to be the answer I was looking for! Now to figure out how to use a Unix time attribute to trigger an automation… hmmmmm

Why not just trigger it from NodeRed?

1 Like

Um… I don’t know. I’ll only using node red because it has a Brewfather integration and home assistant doesn’t. So I viewed it as a way to get the data into Home Assistant

Can you do specific Unix date time based triggers in node red? How would I logically get this data, save it in a variable somehow, then trigger that based off of time?

You will have to use the Big Timer node then.
REMEMBER to set the latitude and longitude or it will not work properly.

1 Like

Thanks again @WallyR

I’m learning a lot. Biggest thing I’ve learned is that Home Assistant is where I want my automations to stay… time based are just easier in there, and I have several other devices that need to change when these automations start, as well as my entire UI which is better controlled from Home Assistant.

To that end, I’ve successfully added a Node Red flow that updates the epoch time string into an input_datetime, which I’ll then run my automation off of. This works, but I would have to do each manually.

I have it set up to split the payload into X number of steps. My question is: can I use the Node Red call service with a variable target? As in, after my split, for each timestamp, update Step X where X is the step number from my array.

I don’t think it’s possibly, as I have to select the Home Assistant Entity from a dropdown, but I figured I would ask!

I’m sure there’s some way using the HA API in Node Red and not the Call Service, but that’s beyond me.

Figured it out! It’s even easier than I expected…

You don’t HAVE to use the dropdown for Entity in the Call Service node, you can call a node-red msg using {{ payload.whatever }}

Super easy, solved now!

1 Like