Virtual devices / data storage

Hi everyone.

I want to create some similar flows in NodeRed, all of them being a more dedicated device tracker for my needs.

I want to store different complex data structures from NodeRed in HA. (more detailed example idea below). I know that I can use helper entities, but with multiple implementations, the number of of needed entities would increase a lot, and they are within a structure, so hard to organize later. Also it is possible to use one helper with attributes, but the attribute support in NodeRed is not really good and they should no longer be used (as far as I found out).

So, here is my example:
I want to create a complex device reminder to help the people with ADHD living here. For example for the washing machine. It should have different information, and handle reminders based on them.
Reminders will be telegram messages and Alexa voice responses.

  • current state of the device (Empty, Ready & loaded, running, finished & loaded,ā€¦)
  • starting time
  • starting power total
  • total power (last run)
  • total cost (last run)
  • total time (last run)
  • already reminded?
  • last reminder time

With these information, I can send a first message when the washing mashine starts (as it is often pre-loaded, but the started lated depending on the hourly energy prices), when it is finished (including time, costs and power consumption) and later if it is not unloaded and still contains wet clothes.

So, now to the question I have here to create it:
As you can see, there are a lot of entities needed to store the data in HA (I want to store it there, so that I can see the current values in a dashboard). And I could create the all as single entitties. Mut that is quite a mess of unstructured data points, and I want to have a single virtual device or object (as you would call it in programming) with different values.
Is there any way to crate custom devices not linked to an integration and not physically existing (ā€œhelper devicesā€). or any other way to store this complex data structure?
I could store a JSON with all data, but then it is quite complicated to show them in the dashboard (creating template helper for everything I want to show).

Thanks for your help,

If you install the nodered companion app you can create sensors from nodered.

This does not really solve my problem. I still need to create a lot of unstructured entities, and they will always show up in my HA without being linked to any kind of device.
I am fine to create the data structures I need in HA (as I also need to show them in dashboards,ā€¦)

And it seems that this integration also does not support grouping multiple entities to any kind of virtual device

Why would it need to be a device?
A sensor with n number of attributes will hold all the information in one place

Attributes are more or less discontinued in HA for the future (for all means that I have read so far) and should not be used in newer implementations. Starting with a legacy structure now does not seem to be a good idea.

Also handling attributes in NodeRed is not really good, as you always need to create template sensors for them for e.g. trigger flows on change (and that works against having an easy to maintain data structure in the future). Also displaying attributed in dashboards also needs additional work.

If I miss out on anything, please let me know. But I am really confused that there seems no real way to store a more complex data structure in HA that can be easily accessed and changed from HA and from NodeRed.

Where have you seen this?

Why would you need that?
A sensor node in node red gives you a sensor with the attributes

Yes, I believe that is the ā€˜grand planā€™. Devices to become the main ā€˜thingā€™ with entities as attribute characteristics. However, since devices are currently just a label for grouping entities, and since entities require attributes to function (eg friendly_name), it is going to be quite a while (and a great deal of upheaval) before I think anything will change on that front.

There are many of us with a huge amount of investment in the current legacy structure. Waiting for the new dawn and the sunny uplands you will miss out on actually getting stuff done and working.

I think we need to differentiate between Node-RED and Home Assistant. Node-RED eats complex data structures for breakfast, and I have never had any problems with using attributes in Node-RED. In fact, most of my work is done on complex data structures in Node-RED, which I pass to Home Assistant via attributes in sensorsā€¦
Home Assistant is, of its own, designed to work around entity states. Yes you can get at attributes (display them in entity cards, use templates to extract them, graph them, display tables of arraysā€¦).
To trigger a flow on a change, you use the State: entity node in Node-RED. HA will trigger a ā€˜change eventā€™ on the event bus when either the state changes or one of the attribute values changed. No big deal

The following page, in HA, is for solar forecasts, which are computed in Node-RED. Almost all of the data you see here are attributes passed from Node-RED to HA in just three sensors, all data and processing being run from Node-RED.

These are complex data structures that are created and manipulated in Node-RED, and then a summary passed to HA as required for display / use in automations.

I think that the heart of the matter here is that Home Assistant is an event-based state-model machine. It has ā€˜thingsā€™ that have ā€˜statesā€™, and these thing-states represent something in the real world. ā€˜Thingsā€™ (entities) are created by integrations that connect to the real world and keep the thing-state value updated (events). This allows us to see (on a screen) the state of things and to respond to state changes (events) and in a few cases make changes to the real world using the integration.
HA holds no data, other than the state model, and a record of the history of the state model. It is not (primarily) a data-base or data-modelling / data-manipulation tool, and therefore cannot really be used as such.

Node-RED in contrast is a full programming language. It has data storage and manipulation capability. Node-RED can connect with HA quite easily.

For your interest, here is the additional work required to display an entity (sensor) attribute value in Home Assistant.

I agree that HA attributes are not easy to understand at first and perhaps a bit scary, but once I (finally) got my head around what HA entities and attributes actually are, and how to use the WebSocket Sensor node, it all fell into place.

And, no, HA is not a tool you can (easily / at all) use for creating data structures out of the devices / entities.

1 Like