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

Disconnected from MQTT without further errors #2

Closed
vicvancooten opened this issue Aug 14, 2019 · 6 comments
Closed

Disconnected from MQTT without further errors #2

vicvancooten opened this issue Aug 14, 2019 · 6 comments

Comments

@vicvancooten
Copy link

vicvancooten commented Aug 14, 2019

I've implemented this script according to the instructions. I couldn't get the script working via crontab (that seems to get reset on hass.io), so I use a home assistant service to trigger a shell script instead. As soon as I trigger the service, this happens in the log for mosquitto.

1565777762: New client connected from [some-ip] as auto-67CD84C1-589C-4DBD-B13E-43E81E26EF8B (p2, c1, k60, u'miscalescript').
1565777767: Socket error on client auto-67CD84C1-589C-4DBD-B13E-43E81E26EF8B, disconnecting.

I know the information in the script is correct, because the client clearly connects. If I do anything else, it doesn't appear in the logs for mosquitto.

Home assistant's logs indicate nothing.

I would love to be able to fix this, because it seems very useful 😄

@lolouk44
Copy link
Owner

At the moment I have no idea if it would or would not work on hass.io.
All I know is that the script must be executed by a user with root privileges. As far as I know HA doesn't run as root, so calling a script from HA will not run it as root and will therefore fail.
This would most likely have nothing to do with MQTT, more likely the script runs, connects to MQTT, then fails due to lack of permission and stops/exits which disconnects MQTT.
try to SSH on the pi and run the script as the user hass.io runs under, I suspect you'll see the same errors as above.
Try and run the script as root and I suspect it won't fail.
I'm a bit surprised cron jobs get reset... if you add a job to your crontab, save and exit then reboot the pi, can you then edit the crontab and see the job has been deleted?

@vicvancooten
Copy link
Author

Quick reply, cheers.

It makes sense the script doesn't get executed as root. It could have something to do with the fact that SSH for hass.io uses a docker container. Every time the container restarts, I lose the crontab functionality. I generally only run that container when I need it. But, to be fair, right now I have it in crontab (in the container), and it still doesn't seem to run. No errors either. But nothing connects to the broker and no home assistant errors. I'll try to append sudo as a command now, see what it does.

If I just execute in shell I get an error bluepy doesn't exist. I don't know how to load that in that environment.

@lolouk44
Copy link
Owner

lolouk44 commented Aug 14, 2019

Are you able to ssh outside of the container? I really have no idea how hass.io "behaves" compared to a regular Linux install. But on a Pi if you add a blank file called ssh on the root of the SD card it allows you to ssh into it. Dunno if this feature is kept in hass.io. If it is then you can do all the things you need outside of the hass.io container and it should work

@vicvancooten
Copy link
Author

vicvancooten commented Aug 14, 2019

AFAIK (not extremely technical, so I may get things wrong) hass.io is a hypervisor that loads and manages multiple containers with functionality. Home assistant is one of those containers. Then you install add-ons (also containers) that add functionality. SSH is one of those add-ons. It works great, including remote access. But you can't access every linux function. For example, I would have no clue how to use apt. I also don't know how to get pip in there. Maybe it's possible, but I just don't know how 😅 Root access is possible, but it's access to the container. I know it's possible to turn off protection mode and "escape" to the system, but even then your access is limited.

Long story short, hass.io makes things easier as a user, but power user features such as these are a bit harder.

I'll continue looking and will of course let you know if I find a way.

@lolouk44
Copy link
Owner

Thanks. I've done a quick search onhass.io and crontab and it doesn't appear possible to access the main OS's crontab.
Guess if you want to thinker you may need to step out of the "easy on user" mode and step into the "I'm a tinkerer" mode, in other words "ditch" hass.io and use hassbian ;)
If you do find a way to access the main OS' crontab, yes please do share :)
For now I'll close this issue if you don't mind

@vicvancooten
Copy link
Author

That's fair! Your library is aimed at hassbian and that's what it does 👍

For me hass.io is the way because it's a mad convenient way to do more than just automate your home. Besides this scale I have no further power use requirements. But I'll find a way!

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

No branches or pull requests

2 participants