daniloc / picow_homeassistant_starter Goto Github PK
View Code? Open in Web Editor NEWEverything you need to get started with your own Intranet of Things, using the high-quality, low-cost Pico W as the backbone.
License: MIT License
Everything you need to get started with your own Intranet of Things, using the high-quality, low-cost Pico W as the backbone.
License: MIT License
If MQTT_LOGIN & MQTT_PASSWORD left blank:
#define MQTT_LOGIN ""
#define MQTT_PASSWORD ""
Application still indicates that it connects to the MQTT Broker but Controls do not work.
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
21:39:44.381 > Connected to
21:39:44.381 > Tajin
21:39:44.382 > Connecting to MQTT
21:39:44.383 > Connected to MQTT broker
If I add the LOGIN and PASSWORD everything works fine.
So I 'm not sure where the issues is here but I'm trying to connect two Pico Pi MQTT devices to HA. I can see that both are reporting unique ID's to HA's broker but only a single device is being discovered in HA. Though I don't think they need it, they both have unique names but otherwise the firmware is probably identical.
I belive the four clients are: 1: HA's MQTT Broker, 2: MQTT Explorer, 3: Pico Pi, 4: Pico Pi
And indeed the device looks correct:
I feel like this is an issue with mosquitto but it could be due to a discovery issues with this project or AHA.
I was testing this project on LInux and getting this issue:
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1
I was due to firmware running on the Pico Pi W not having a serial port. To resolve the issues I uploaded a sketch from the ASCII Table Sketch from the Arduino IDE.
I'm not sure how to fix this from Platform IO.
It might be nice if the README.md had a bit of guidance on this issue.
@daniloc How do you build this project? I've been working in Linux but I'm trying to build on my Windows laptop and have all kinds of issues. If I use the default raspberrypi package I get a missing package or platfom json file (I can't see the exact one now but I'll up date this later. If I try to use the same commit of the pico package that I"m using on my Linux machine I take like 5-15 minutes to clone a bunch of stuff then ultimately fails. If I had to guess your using a mac (especially becuase of the mac-post-upload.py script in the package).
Suggestion: Add note in HAIntegration.cpp that HASwitch(uniqueid) must not contain spaces.
HASwitch led("led"); // unique identifier must not contain spaces
Trying to compile the project I get the following errors:
Compiling .pio/build/pico/lib74c/home-assistant-integration/HAMqtt.cpp.o
src/HAIntegration.cpp:15:26: error: no matching function for call to 'HASwitch::HASwitch(const char [4], bool)'
15 | HASwitch led("led", false);
| ^
src/HAIntegration.cpp:36:9: error: 'class HASwitch' has no member named 'onStateChanged'
36 | led.onStateChanged(switchHandler);
| ^~~~~~~~~~~~~~
Compiling .pio/build/pico/lib74c/home-assistant-integration/device-types/HABaseDeviceType.cpp.o
*** [.pio/build/pico/src/HAIntegration.cpp.o] Error 1
Recently I've noticed that if my router is power cycled that the PicoPi either doesn't reconnect to the router or HA (not sure which yet). Not sure if this issue is best addressed by this project or the upstream arduino-home-assistant project.
I would be nice if the HABaseDeviceType class had a pointer to a struct (or class) that could be used to hold arbitrary data per users need. This would allow adding information that could be retrieved by a generic handler. This would allow you to do things like this:
class ZoneData {
public:
uint8_t led_pin;
uint8_t ssr_pin;
};
void HAIntegration::switchHandler(bool state, HASwitch* sender) {
digitalWrite(((ZoneData)sender->data).led_pin, (state ? HIGH : LOW));
digitalWrite(((ZoneData)sender->data).ssr_pin, (state ? HIGH : LOW));
sender->setState(state); // report state back to Home Assistant
}
I'm trying to make a very simple system that makes an LED fade up and down when a switch hasn't been turned on. Frustratingly I cannot get analogWrite to work in any way whatsoever.
To confirm, I've stripped back main.cpp of pretty much everything but Arduino.h and even there, I cannot turn on the LED using analogWrite, but I can with digitalWrite.
I'm struggling to think what I could be doing wrong, I've tried every possible google search I can think of but everything is for C or python in ArduinoIDE but never C++ in VSCode so even though this seems a bit off topic for the scope of this project, I'm hoping you'll be happy to assist anyway seeing as I'm using it as a basis :(
My Linux system complains that osascript doesn't exist in the post-upload step, due to mac-post-upload.py. Could platformio.ini be set up to only run this step on Mac systems? Or maybe add an OS check to mac-post-upload.py?
I was able to get the upload to work by just removing the script from platformio.ini.
(I may submit a pull request for this later, just wanted to throw it out there in case someone else wanted to get to it before me since it's probably not too complicated)
Enabling the LWT (Last Will and Testament) feature requires adding three lines of code and add the very cool functionality of giving HA the ability to detect if the device looses power.
device.enableSharedAvailability(); // [OPTIONAL] Enables the ability to set the on/off line status of the device
device.setAvailability(true); // Set the device to on-line
device.enableLastWill(); // [OPTIONAL] Allows HA to detect when the device losses power (and thus disable the controls in the HA UI)
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
And for some reason one of the switches comes up unnamed ("MQTT Switch").
Rename HAIntegration::configure() to either HAIntegration::begin() or HAIntegration::setup() for more orthogonal naming with the Wiring/Arduino naming conventions.
I feel like begin() better matches other Arduino classes in how its used, but because of the loop() it really feels like it should be called setup().
Frankly, configure() doesn't really bother me either, but I think begin() or setup() really hits home as to what this function is doing and where it probably should be called from.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.