Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to home assistant 0.100.1 sensor #2

Closed
wants to merge 13 commits into from

Conversation

PieterGit
Copy link

Work in progress...

I'm trying to get this module into shape to run with latest home assistant.
If it works I would like to work on seeing if it can be integrated with the default components.

@JonasR- @salleq @peltsippi Are you interested to help with this effort?

@PieterGit
Copy link
Author

PieterGit commented Oct 12, 2019

Current state: It loads in hassio 0.100.1 version, but unfortunately the bluetooth reading does not seem to work yet. I see the following error in /config/home-assistant.log

2019-10-12 22:02:15 ERROR (SyncWorker_0) [custom_components.ruuvi_hass.sensor] E
rror on polling sensors
Traceback (most recent call last):
  File "/config/custom_components/ruuvi_hass/sensor.py", line 88, in poll
    self.conditions = self.RuuviTagSensor.get_data_for_sensors(self.mac_addresse
s, self.timeout)
  File "/usr/local/lib/python3.7/site-packages/ruuvitag_sensor/ruuvi.py", line 9
3, in get_data_for_sensors
    for new_data in RuuviTagSensor._get_ruuvitag_datas(macs, search_duratio_sec,
 bt_device=bt_device):
  File "/usr/local/lib/python3.7/site-packages/ruuvitag_sensor/ruuvi.py", line 1
34, in _get_ruuvitag_datas
    for ble_data in data_iter:
  File "/usr/local/lib/python3.7/site-packages/ruuvitag_sensor/ble_communication
.py", line 110, in get_datas
    procs = BleCommunicationNix.start(bt_device)
  File "/usr/local/lib/python3.7/site-packages/ruuvitag_sensor/ble_communication
.py", line 76, in start
    exit(1)
  File "/usr/local/lib/python3.7/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: 1

@pschumi @JonasR- @salleq @peltsippi @ykii if you know how to help fix this, please let me know. Giving up for tonight. Can it be some kind of bluetooth permission problem that needs to be fixed?

@peltsippi
Copy link

peltsippi commented Oct 15, 2019 via email

@peltsippi
Copy link

peltsippi commented Oct 15, 2019

Just got my homeassistant running and this branch seems to run perfectly.

Something I dug from my original hass installation notes:
make sure you have both:
-hcitool
-lib2cap-bin

And make hcitool runnable with non-root users using lib2cap-bin. Not sure if this is it because hcitool seems to be running with sudo in my homeassistant log. But worth trying out.

https://unix.stackexchange.com/questions/96106/bluetooth-le-scan-as-non-root

There is comment about LE scan requiring root privilege by default

@JonasR-
Copy link
Collaborator

JonasR- commented Oct 15, 2019

Hey guys,

thanks for the work done and sorry for my absence.
I promise to take a look at this pr this week and test it out in my environment

@peltsippi
Copy link

peltsippi commented Oct 17, 2019

It seems that my config cannot handle Hass restarts. Or then it just stops working otherwise after a while. Probably something to do with hcitool. I'll try to figure out what goes south.

@ykii
Copy link

ykii commented Oct 17, 2019

My config works for 1-2 days, but then suddenly it stops receiving data from ruuvitag. I haven't had enough time to look into it yet. Cronjob for daily restart in the night time has resolved the issue easy enough.

@peltsippi
Copy link

It seems that now I can't reproduce my issue anymore. Restarting Hass does not break the plugin at the moment. I jumped to new raspbian distro yesterday to get rid of hass openssl issue, otherwise everything is intact.

@JonasR-
Copy link
Collaborator

JonasR- commented Oct 20, 2019

Looks like i also get data. I will watch it for a few days as @ykii had some problems over time

@peltsippi
Copy link

Here is something I dug from the logs:

Syslog

Oct 20 13:19:52 raspberrypi kernel: [110880.711291] Bluetooth: hci0: Frame reassembly failed (-84)
Oct 20 13:19:52 raspberrypi kernel: [110880.711312] Bluetooth: hci0: Frame reassembly failed (-84)
Oct 20 13:19:52 raspberrypi kernel: [110880.711429] Bluetooth: hci0: Frame reassembly failed (-90)
Oct 20 13:19:52 raspberrypi hass[487]: 2019-10-20 13:19:52 INFO (SyncWorker_6) [ruuvitag_sensor.ruuvi] Get latest data for sensors. Stop with Ctrl+C.
Oct 20 13:19:52 raspberrypi hass[487]: 2019-10-20 13:19:52 INFO (SyncWorker_6) [ruuvitag_sensor.ruuvi] Stops automatically in 3s
Oct 20 13:19:52 raspberrypi hass[487]: 2019-10-20 13:19:52 INFO (SyncWorker_6) [ruuvitag_sensor.ruuvi] MACs: ['xx:xx:xx:xx:xx:xx']
Oct 20 13:19:52 raspberrypi hass[487]: 2019-10-20 13:19:52 INFO (SyncWorker_6) [ruuvitag_sensor.ble_communication] Start receiving broadcasts (device hci0)
Oct 20 13:19:56 raspberrypi kernel: [110885.311899] Bluetooth: hci0: command 0x1003 tx timeout
Oct 20 13:19:58 raspberrypi kernel: [110887.391905] Bluetooth: hci0: command 0x1001 tx timeout
Oct 20 13:20:00 raspberrypi kernel: [110889.471881] Bluetooth: hci0: command 0x1009 tx timeout
Oct 20 13:20:02 raspberrypi hass[487]: Disable scan failed: Connection timed out
Oct 20 13:20:02 raspberrypi hass[487]: 2019-10-20 13:20:02 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.xxxx_pressure is taking over 10 seconds
Oct 20 13:20:05 raspberrypi hass[487]: Can't init device hci0: Connection timed out (110)
Oct 20 13:20:05 raspberrypi hass[487]: Could not open device: No such device
ct 20 13:20:20 raspberrypi hass[487]: 2019-10-20 13:20:20 WARNING (MainThread) [homeassistant.components.sensor] Updating ruuvi_hass sensor took longer than the scheduled update interval 0:00:30

Kern.log seems to be filled with
Oct 20 13:07:26 raspberrypi kernel: [110134.572778] Bluetooth: hci0: Frame reassembly failed (-84)

And auth.log:
Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0) Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:19:52 raspberrypi sudo: homeassistant : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/kill -s SIGINT 21074 Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0) Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:19:52 raspberrypi sudo: homeassistant : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/kill -s SIGINT 21085 Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0) Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:19:52 raspberrypi sudo: homeassistant : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/hciconfig hci0 reset Oct 20 13:19:52 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0) Oct 20 13:20:02 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:20:05 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:20:05 raspberrypi sudo: homeassistant : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/hcitool lescan --duplicates Oct 20 13:20:05 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0) Oct 20 13:20:05 raspberrypi sudo: pam_unix(sudo:session): session closed for user root Oct 20 13:20:05 raspberrypi sudo: homeassistant : TTY=pts/0 ; PWD=/ ; USER=root ; COMMAND=/usr/bin/hcidump --raw

So it seems to suggest hcidump and/or hw not working as supposed to.

@keskikou
Copy link

@PieterGit any updates on your bluetooth permission problem?

@peltsippi
Copy link

Here is something I dug from the logs:
...
So it seems to suggest hcidump and/or hw not working as supposed to.

This issue might be involved in homeassistant core / similar instead. I added automation to export all temperatures every 15 minutes to text file and reading ruuvitags froze 6-10 hours after fresh reboot. I disabled the automation and now everything seems to work perfectly again with reboot every 24 hours.

Copy link

@peltsippi peltsippi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this working with 5 ruuvitags pretty much reliably with rpi3+ by doing following modification in sensor.py (new value 60, was 10) :

MAX_POLL_INTERVAL = 60 # in seconds, was 10

So IMHO this should be ready to be approved with that modification. Further development idea: calculate MAX_POLL_INTERVAL based on amount of sensors total. Easiest formula for testing could be for example 10 secs per one sensor defined.

@peltsippi
Copy link

I was just too hasty, see updated readme and version that works for me at https://github.com/peltsippi/ruuvi-hass

There already were variables available for all kinds of customizations, they just were not documented anywhere.

@peltsippi
Copy link

Have been doing tests and no luck with longer poll intervals. Works 90% of the time just fine for 24+hrs but sometimes freezes after couple hours. Currently I am testing python version used in other pull request.

@sergioisidoro
Copy link
Member

Closed in favor of #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants