Closed dwlyles closed 2 years ago
Looks like I did not properly check for the existence of values somewhere, but it is not immediately apparent where I went wrong. Can you please add the following print statements after the line 340 at the start of the if block (i.e., indented right under "if name in SENSORS:"):
print("s: "+str(s))
print("name: "+name)
print("sensors: "+str(SENSORS[name]))
I believe the output from that will help me figure out where I went wrong. Thank you.
It would also be helpful if you could share the "devices" section of your options.json file (please make sure not to include any passwords). Thank you.
Welp it looks like the bluetooth on my rpi-3 wont place nice tonight. Just trying to run the airthings find_wave command starts to scan and then for some reason fails. I'm going to keep trying though.
Traceback (most recent call last):
File "/home/pi/airthings-mqtt-ha/src/find_wave.py", line 43, in <module>
devices = scanner.scan(2.0)
File "/home/pi/.local/lib/python3.9/site-packages/bluepy/btle.py", line 853, in scan
self.process(timeout)
File "/home/pi/.local/lib/python3.9/site-packages/bluepy/btle.py", line 829, in process
self._mgmtCmd(self._cmd())
File "/home/pi/.local/lib/python3.9/site-packages/bluepy/btle.py", line 312, in _mgmtCmd
raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scan'
Here's the config you asked for as well.
{
"devices": [
{
"mac": "d8:71:4d:af:0a:e2",
"name": "Master Bedroom"
}, {
"mac": "d8:71:4d:af:0a:f0",
"name": "Boy's Room"
}, {
"mac": "d8:71:4d:a9:d3:e2",
"name": "Kitchen"
}, {
"mac": "d8:71:4d:a9:cc:2b",
"name": "Studio"
},{
"mac": "d8:71:4d:af:07:2d",
"Name": "Girl's Room"
}],
"refresh_interval": 150,
"retry_count": 10,
"retry_wait": 3,
"log_level": "INFO",
"mqtt_discovery": false,
"mqtt_retain": false,
"mqtt_host": "",
"mqtt_username": "",
"mqtt_password": ""
}
I think I see the problem. In your configuration file you last device uses "Name" with a capital N instead of "name" with a lower case N. I think that is why you are getting the key error. Please give that change a try and see if it fixes the issue. Perhaps I should add some checks for the config file format to give more helpful errors in the future.
I've added the
print ("s: "+str(s))
print ("name: "+name)
print ("sensors: "+str(SENSORS[name]))
but i dont see any additional output.
Also, updating the config "Name" to "name" also didnt change the results of the scan.
Those changes will not help with your scanning issue, which appears to be something else. I know others have had issues with the integrated bluetooth on the rasberrypi (particularly the rpi4) but I have not had any issues when I occasionally use an rpi3 that I have doing other things. If you have not already, consider rebooting the pi to see if that helps with the scanning issue.
After installing the some bluetooth visual software. Making sure bluetooth stays "enabled" reboot and presto! All 5 devices look to be pulling values and reporting to HA. Thank you again!
Good to hear; glad it is working for you (and good to know that it will work with 5 devices).
I really appreciate your script here and trying to use it to its fullest ability. So thank you 1st and foremost.
Currently able to send 4/5 devices to HA Broker. airthings-mqtt-ha.py seem to see and pulls data for all 4 devices.
After this error, The scripts reports all the values for the temp, hum, and voc. but it just stops there, the last device in my config will not show up in HA. If this an HA issue or can i tweak the script? I have very little python experience, but i tend to have good success though google resarch. Although, im stuck here lol