twocolors / node-red-contrib-esphome

Node-RED nodes to ESPhome devices
MIT License
18 stars 5 forks source link

Feature request get all entities of device #13

Closed guyluz11 closed 1 year ago

guyluz11 commented 1 year ago

I am setting my node-red by creating the JSON with code and importing it to node-red.

Currently there is no way for me to get all the entity's id and types, it is not saved on ESPHome device node and there isn't any node that can retrieve the list of entities for a specific device.

I would love to see all of the available entities' data saved under the device node including all the available data for each entity (name, type, id, pin?, platform?, output?).

ondonadas commented 1 year ago

@guyluz11 I'm not involved in any way in this project, but I'm my case I can retrieve all entities from esphome on node red, as long as I use API>password instead of API>key

guyluz11 commented 1 year ago

Interesting, can you give an example? Not sure that I understand how you did it.

ondonadas commented 1 year ago

@guyluz11 yes not sure if you mean the same. I refer to discover and get esphome devices entities inside node red dashboard. Later I'll share some images of you need it

ondonadas commented 1 year ago

@guyluz11 take a look to the image. As you can see entity shows the components I've declared in esphome. It only works as long as you declare api>password inside your device yaml file.

Screenshot from 2023-03-12 21-05-11

image

guyluz11 commented 1 year ago

I have managed to configure espHome api nod but without password.

The entities of this device is the next step and I saw that there is a NodeRed network request that I can use for that

guyluz11 commented 1 year ago

I found 2 post requests that are open from this package by node-red

A request to get all discovered ESPHome devices in the network.

post(
      Uri.parse('http://localhost:1880/esphome/discovery'),
      encoding: Encoding.getByName('utf-8'),
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      body: {
      },
    );

To get all entities of a device by esphome device node ide

post(
      Uri.parse('http://localhost:1880/esphome/entities'),
      encoding: Encoding.getByName('utf-8'),
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      body: {
        'deviceNode': espHomeDeviceId,
      },

But no way to set up a device node including a password :(

guyluz11 commented 1 year ago

Found with the help from the discord server that I can use the API and include password in the request using

 {
      "id": "$id",
      "type": "$type",
      "name": "$name",
      "target": "",
      "host": "$host",
      "port": "6053",
      "credentials": {
            "password": "$password"
      }
    }
guyluz11 commented 1 year ago

So I have everything that I need in order to discover and create devices with entities from my code.

Thanks

twocolors commented 1 year ago

@guyluz11 oh, oh, oh it's okey!

if you won, you can make pull for example like https://github.com/twocolors/node-red-contrib-esphome/blob/main/examples/SwitchOFForON.json