daniloc / PicoW_HomeAssistant_Starter

Everything you need to get started with your own Intranet of Things, using the high-quality, low-cost Pico W as the backbone.
MIT License
198 stars 20 forks source link

Extraneous MQTT Switch #9

Closed JacobChrist closed 1 year ago

JacobChrist commented 1 year ago

Initial issue was that not all HASwitches were showing up:

HASwitch led("led");
HASwitch zone[] = { 
    HASwitch("Zone0"),
    HASwitch("Zone1"),
    HASwitch("Zone2"),
    HASwitch("Zone3"),
    HASwitch("Zone4"),
    HASwitch("Zone5"),
    HASwitch("Zone6"),
    HASwitch("Zone7"),
    HASwitch("Zone8"),
    HASwitch("Zone9"),
};

(snip)

    // handle switch state
    led.onCommand(switchHandler);
    led.setName("FlowBot LED"); // optional

    // Zone state
    for(uint8_t i = 0; i < 10; i++)
    {
        zone[i].onCommand(switchHandler);
    }
    zone[0].setName("Zone 0"); // optional
    zone[1].setName("Zone 1"); // optional
    zone[2].setName("Zone 2"); // optional
    zone[3].setName("Zone 3"); // optional
    zone[4].setName("Zone 4"); // optional
    zone[5].setName("Zone 5"); // optional
    zone[6].setName("Zone 6"); // optional
    zone[7].setName("Zone 7"); // optional
    zone[8].setName("Zone 8"); // optional
    zone[9].setName("Zone 9"); // optional

image

And for some reason one of the switches comes up unnamed ("MQTT Switch").

JacobChrist commented 1 year ago

Found what was limiting the number of HASwitches and changed the maxDeviceTypeNB to resolve:

    explicit HAMqtt(
        Client& netClient,
        HADevice& device,
        const uint8_t maxDevicesTypesNb = 12
    );

However I still have a extra non-responsive MQTT Switch

JacobChrist commented 1 year ago

I'm wondering if this is not an issue in HA itself. When I added another HASwitch then removed it, it now appears in the settings but is no longer in code "FlowBot ABC". Maybe its a string left in the MQTT server. image

JacobChrist commented 1 year ago

Interestingly enough, the names of the Entity created is based on when I created the entity and what I was doing at the time of creation. That is to say they are named inconsistently and this may be related: For example:

image vs image

Zone 3 was around before I figure out how to name the zones and get more than 6 switches so it got a generic name. Zone 4 was first created with a name after the max number of devices was created.

The two non-working switches have names associated with switches I created then removed while testing different confiturations:

image image

I've tried to delete entities but I get this message:

image

Only 0 selected entities can be removed.
You can only remove 0 of the selected 1 entities. Entities can only be removed when the integration is no longer providing the entities. Sometimes you have to restart Home Assistant before you can remove the entities of a removed integration. Are you sure you want to remove the removable entities?
daniloc commented 1 year ago

Good catch on maxDevicesTypesNb. This is another one where I think you'll get further working directly with the maintainers of Arduino Home Assistant. This project is just an example to show how to get started using it. This issue, for example, came up just last week.

JacobChrist commented 1 year ago

I'm pretty sure this is an issue with HA and the way MQTT caches messages. If I delete the device then the issue goes away. image

Also, all the Entity ID's update to the correct names set in firmware. image