Comments (10)
Upstream issue. You can find a workaround here:
dawidchyrzynski/arduino-home-assistant#183
tl;dr: arduino-home-assistant
doesn't unique the entities in its 2.0 release; use my fork that does instead.
from picow_homeassistant_starter.
@daniloc Thanks for this, I've merged in your changes but it doesn't seem to have resolved the issue.
from picow_homeassistant_starter.
You'll probably need to delete the device in Home Assistant and re-add it. Try that out and let me know how it goes.
from picow_homeassistant_starter.
Thanks for the help BTW...
I've deleted the homeassistant and aha nodes in MQTT Explorer which causes the 1 device and 11 entities to disappear from HA.
It looks like your trying to create a uniqueId based on the mainUniqueId and uniqueIdSuffix. This id should have an "" between the mainUniqueId and uniqueIdSuffix. I'm not seeing any id's with underscores between them in MQTT Explorer.
This picture was taken after the old nodes have been deleted and uploading new code to the boards:
from picow_homeassistant_starter.
I think I found the issue here. If when the HADevice object is instantiated you pass in a uniqueId
then this bit of code works and the entity uniqueId
is prepended with the mainUniqueId
. However, if you use setUniqueId after the device object has been instantiated this does not work.
Here is json string when creating the device using: `HADevice device("myUniqueId")
{
"name":"FlowBot LED",
"uniq_id":"myUniqueID_led","ic":"mdi:led-outline",
"dev":{
"ids":"myUniqueID",
"name":"FlowBot by PONTECH","sw":"0.1"
},
"stat_t":"aha/myUniqueID/myUniqueID_led/stat_t",
"cmd_t":"aha/myUniqueID/myUniqueID_led/cmd_t"
}
I'm pretty sure this is happening because the HASwitch instances I'm creating are globals and since they inherent from HABaseDeviceType and since this _uniqueId has not been set yet it defaults to using just the HASwitch uniqueId.
from picow_homeassistant_starter.
I have confirmed that this is the issue, I now have two devices and 22 entities in HA. I have to manually created the uniqueId passed when the HADevice object is instantiated. This is sufficient for now, but there should probably be a ways to either:
- Pass the mac address in to the HADevice object when declared globally.
- Have all the entity uniqueId's update when a setUniqueId call is made before mqtt.begin().
from picow_homeassistant_starter.
Iiiinteresting, and annoying. Come to think of it, I vaguely remember encountering this on ThermTerm, and you can see evidence of it in the weirdly complex constructor for HAInterface
I ended up with:
HAInterface::HAInterface() : macAddress_(generateMacAddress()),
haDevice_(macAddress_.c_str()),
mqtt_(client, haDevice_),
temperatureSensor_("temperature"),
humiditySensor_("relative-humidity"),
lightSensor_("light-intensity"),
alertTrigger_("alert-trigger"),
hvacDevice_(
"heat-pump",
HAHVAC::TargetTemperatureFeature |
HAHVAC::PowerFeature |
HAHVAC::ModesFeature |
HAHVAC::FanFeature)
{
}
The inside baseball here is that I built this starter before a-h-a 2.0 dropped and it seems to be a substantially ground-up rewrite where some of these small side effects haven't been caught. It fixed other bugs, though, and added deeper functionality so I think it's net positive despite this.
I would be curious if this particular failing is a result of my hacky fork though.
from picow_homeassistant_starter.
I'm made a total bodge fix so I don't have to manually type in mac address when the HADevice is instantiated. Here is my solution:
- I turned my HADevice, HAMqtt and HASwitch into global pointers.
HADevice* pDevice;
HAMqtt* pMqtt;
HASwitch* pLed;
- I build a uniqueIdStr then create my objects and updated my global pointers like this:
char uniqueIdStr[30];
void HAIntegration::configure() {
//Set device ID as MAC address
byte mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
snprintf(uniqueIdStr, 20, "HALed-%02x%02x%02x%02x%02x%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6]);
Serial.println(uniqueIdStr);
pDevice = new HADevice(uniqueIdStr);
pMqtt = new HAMqtt(client, *pDevice);
static HASwitch led("LED"); // unique identifier must not contain spaces
pLed = &led;
- If I need to access my objects outside of HAIntegration.cpp I do it like this:
pLed->getCurrentState()
Don't forget to add the pointers to the HAIntegration.h file as externs.
here is a published message:
{"name":"HALed LED","uniq_id":"HALed-28cdc10f56bb_LED","ic":"mdi:led-outline","dev":{"ids":"HALed-28cdc10f56bb","name":"HALed","sw":"0.1","mf":"PONTECH.com","mdl":"HALED100"},"avty_t":"plp/HALed-28cdc10f56bb/avty_t","stat_t":"plp/HALed-28cdc10f56bb/HALed-28cdc10f56bb_LED/stat_t","cmd_t":"plp/HALed-28cdc10f56bb/HALed-28cdc10f56bb_LED/cmd_t"}
I'm not sure I would recommend this for human consumption but it might be worth putting on a branch for those that are not faint of heart.
from picow_homeassistant_starter.
Ideally you should be able to create all the objects and update the uniqueId's before use and avoid the use of pointers.
from picow_homeassistant_starter.
BTW, I have five Pico Pi's talking to HA and updating the mac address before I uploaded to a board was getting annoying and difficult of keep track of.
from picow_homeassistant_starter.
Related Issues (14)
- Upload fails on Linux due to Mac-specific script in platformio.ini HOT 1
- Errors trying to compile HOT 3
- Error: Please specify `upload_port` for environment or use global `--upload-port` option. HOT 1
- Missing MQTT_LOGIN & MQTT_PASSWORD still indicates connected to MQTT broker. HOT 6
- Suggestion: Add note in HAIntegration.cpp HOT 3
- Extraneous MQTT Switch HOT 5
- Feature Request: Add pointer in HABaseDeviceType to a generic struct (or class) HOT 3
- analogWrite doesn't seem to work HOT 4
- Reconnect to router / HA after router power cycle. HOT 1
- [FEATURE] Enable Last Will and Testament HOT 2
- [SUGGESTION] Rename HAIntegration::configure() to either HAIntegration::begin() or HAIntegration::setup() HOT 1
- HAMqtt::etDataPrefix() misses some cases (avty_t = online) HOT 2
- Build system question HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picow_homeassistant_starter.