How do I create a Device with Entities, not just a list of entities?

One thing I’ve always wondered.
How do I create a ‘Device’ so all these Entities are seen as a Device with the Entities (as ESPHome etc do for me).
I have an incoming JSON string collected from an MQTT server and I split it up, first by device (just mine), then to create the Entities.
Am I missing something, is it possible to create the device ?

Currently

Typical string collected from MQTT server (this is the bottom of the two devices.)

{"dev":"CHASR-1B2C3D4E-1","PM25":"1.7","PM10":"7.3","temp":"9.7","pressure":"1017.0","humidity":"68.0","timestamp":"2022-02-23T10:53:30+00:00"}

Many thanks.

1 Like

Taking a quick look at HA’s documentation and I don’t see a way for a user to create a device. If it doesn’t exist in HA, short of creating your own integration, it won’t be possible from nodered.

1 Like

thanks, probably why I couldn’t find anything then.

Might need to look at another method and forget node-red. Shame it was easy to use and create the entities, just a faff to handle when they’re not seen as a device in HA as just individual entities.

If the idea is to condense this, when you create the entity in nodered, you may add as many attibutes as you need. This could all be in a single entity.

thought I would come back to this, I tried combining as above and it’s just saying some error in the API doing it. I give up, doesn’t seem easy.
Entity API error expected bool for dictionary … (etc)

back to just splitting them all apart long hand.

thanks for trying though, appreciated.

It would seem that you have chosen binary sensor for type. Meaning the primary state would need to be true/false on/off etc. For a number or a string you would use a sensor type.

[{"id":"fc2b40329dc7b990","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"dev\":\"CHASR-1B2C3D4E-1\",\"PM25\":\"1.7\",\"PM10\":\"7.3\",\"temp\":\"9.7\",\"pressure\":\"1017.0\",\"humidity\":\"68.0\",\"timestamp\":\"2022-02-23T10:53:30+00:00\"}","payloadType":"json","x":850,"y":200,"wires":[["9dfe1d80a93aac89"]]},{"id":"9dfe1d80a93aac89","type":"ha-entity","z":"f80b6c338afd5483","name":"test","server":"","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"testnr"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload.dev","stateType":"msg","attributes":[{"property":"PM25","value":"payload.PM25","valueType":"msg"},{"property":"PM10","value":"payload.PM10","valueType":"msg"},{"property":"Temp","value":"payload.temp","valueType":"msg"},{"property":"Pressure","value":"payload.pressure","valueType":"msg"},{"property":"Humidity","value":"payload.humidity","valueType":"msg"}],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":990,"y":200,"wires":[["9555aeef94994375"]]},{"id":"9555aeef94994375","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1230,"y":160,"wires":[]}]

image

1 Like

I did use sensor as it’s obviously not binary, that’s what the error is from.
I’ll update NodeRed again as a new .1 is out so I’ll have another go.
I can see your flow in nodered now, will have a nosey.
Again many thanks. :slight_smile:

I have updated the node-red-contrib-home-assistant-websocket yesterday within node red and what a surprise: it does support now generating devices natively!! Great thank you so much.