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

Examples for manually turning on/off a particular device #1

Closed
pghpete opened this issue Jul 9, 2020 · 5 comments
Closed

Examples for manually turning on/off a particular device #1

pghpete opened this issue Jul 9, 2020 · 5 comments

Comments

@pghpete
Copy link

pghpete commented Jul 9, 2020

First... Thank you sebr for this fantastic work!

Second... Anything I can help with from a user/test perspective, please let me know. Even if its documentation, man pages, etc.

Running the example rest script example_rest_api.py and I do successfully connect and it returns the relevant information. I was wondering if I might ask for another example code file that maybe shows how to do some basic things folks may want to do using this code? (In regards to controlling their device?) Perhaps manually opening/closing valve, setting timers, etc? (If this is even possible?) If you have a way I can donate a few dollars for such a request I would be happy to do so!

How I am attempting to use this code (just for your curiosity). I have a garden raspberry pi 3b+ that acts as a weather station, hose/water relay control, and soon, a water hose turret system to keep the small animals from eating my food if caught by my cameras motion detection. :-) It currently tracks temp/humidity internal to the enclosure, external temp/humidity, solar lux, soil temperature, soil moisture content (in 2 large beds 75sq/ft or 7 sq/meters each), and controls 3 relays that turn on watering to 3 different zones, if a significant amount of rain isn't immediately forecast. Due to their being 7 hoses, a manifold, a relay valve box, etc there are very small leaks from time to time. And to avoid these leaks while the system is not in a watering mode, I have purchases one of the orbit b-hyve smart faucet and wifi relay devices to turn off the water at the source, so the main system can remain unpressurised while not in use. I am attempting to use the rpi to control this device prior to it initiating a watering cycle. Either by BLE or Wifi. Which is where your code would come in extremely handy. :-)

When you have a spare second please let me know if I can help, or donate in any way and if controlling these devices using python is possible.

Regards, and stay safe.

@sebr
Copy link
Owner

sebr commented Jul 10, 2020

Hi @pghpete neat use case!

You could do all of this today if you installed Home Assistant on your RPI :).

This repo is a bit out of date - I maintain bhyve-home-assistant which includes a newer and improved pybhyve implementation in it. You could take a look there for inspiration.

That said, the bhyve-home-assistant repo is designed to be dropped into Home Assistant and enable you to monitor and control bhyve devices with automations (eg motion detection)!! From your description, it would be a great candidate to help you manage your irrigation and weather based automations.

That said, it sounds like you've invested a fair bit into your existing system setup (but I do promise, if you setup Home Assistant you'll be properly hooked).

Unfortunately it's not so simple to turn the devices on or off as REST api is only used to retrieve device information. All device modifications and events are sent through a websocket API. You could take some inspiration from here: https://github.com/sebr/bhyve-home-assistant/blob/main/custom_components/bhyve/pybhyve/client.py#L145

@pghpete
Copy link
Author

pghpete commented Jul 10, 2020

Thanks for your reply! I have dabbled with home assistant and it's on my list of projects to do this winter. :-) So if I am understanding this correctly your websocket python code may be able to be used here?

Yeah the overall goal here is to make these for a family members 60,000 square feet of greenhouses and several acres of fields. (For his small company). I'm on my second version and summer of testing, but eventually the goal is to have them be stand-alone with a cellular internet connection and solar powered by the same panel that runs the well pumps. Every connection, both for the raspberry pi and all external sensors and relays is broken out to a water proof connection point on the box (including 2 usb connections, and an hdmi connection) so someone can just roll up to one with a keyboard and small portable monitor and connect to it (for upgrades and diagnostics) without having to move the box or disconnect any of the sensors.

Here are some shots of it.

20200529_144404

20200528_233421

Being for a family members tiny company I'll eventually just charge him for the cost of parts. :-)

The b-hyve just seamed like a good test device to use as a master shut-off. Especially since they use the Espressif ESP32 boards inside. I haven't cracked one of them open for some hardware hacking yet but that is likely going to happen at some point. :)

@sebr
Copy link
Owner

sebr commented Jul 10, 2020

Very nice @pghpete

I've just updated pybhyve to synch it with the latest implementation. You should now be able to use the examples to both pull data from the rest api or listen (or send) websocket events. If you want to see how to turn a device on or off, see switch.py. You'll have to first pull all the device data using client.devices and parse it.

@pghpete
Copy link
Author

pghpete commented Jul 10, 2020 via email

@sebr
Copy link
Owner

sebr commented Jul 13, 2020

Cheers mate, I'll close this issue for now. Feel free to reach out for anything else!

@sebr sebr closed this as completed Jul 13, 2020
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