sebr / bhyve-home-assistant

Orbit BHyve custom component for Home Assistant
MIT License
255 stars 42 forks source link

Add soil moisture % sensor #133

Open sethhere04 opened 2 years ago

sethhere04 commented 2 years ago

Is it possible to add the soil moisture % as a sensor reported to HA?

sebr commented 2 years ago

@sethhere04 I don't have any of these devices so unfortunately I can't add them. If you are willing to share your account (or create a new one) with me I could take a look.

sethhere04 commented 2 years ago

Sorry, its not a separate device. It’s just the soil moisture % reported in the bhyve app. I was wondering if there is a way to see that in HA.

AnthonyBe commented 2 years ago

I came here to ask the exact same question!

sebr commented 2 years ago

Got it, will take a look and see what I can do!

allistermaguire commented 2 years ago

Hey @sebr, not sure if this is helpful, but moisture is part of the landscape object which you can get with the get_landscape() function. You need to calculate it, percentage = available_water / (field_capacity_depth - replenishment_point) * 100

doe81 commented 2 years ago

+1 on this feature.

kdeyev commented 1 year ago

+1

kdeyev commented 1 year ago

@allistermaguire Hi, I tried to implement the soil moisture sensor in this integration. But there's something wrong with the bhyve API or the way I calculate the moisture value:

import asyncio

import aiohttp

import pybhyve 

async def async_update_callback(data):
    pass

async def main() -> None:
    """Main."""

    websession = aiohttp.ClientSession()

    client = pybhyve.Client(
        "login",
        "passwd",
        session=websession,
    )

    if await client.login() is False:
        raise Exception()

    loop = asyncio.get_event_loop()

    client.listen(loop, async_update_callback)
    all_devices = await client.devices
    for device in all_devices:
        device_id = device["id"]
        for zone in device['zones']:
            zone_id = zone["station"]
            res = await client.get_landscape(zone_id=zone_id, device_id=device_id, force_update=True)
            percentage = res["available_water"] / (res["field_capacity_depth"] - res["replenishment_point"]) * 100
            print(percentage)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

I have 5 zones and all the 5 moisture values were the same 47%, but the Android app shows meaningful moisture values. Do you have any idea how the app calculates these values?

allistermaguire commented 1 year ago

Hi @kdeyev, I have had a look and I was mistaken, I assumed 'available_water' could be used to retrieve level as well as set it, but that is not the case.

Looking at it more from what I can capture from the app, it looks like it is calculated from the 'watering_plan' returned from api.orbitbhyve.com/v1/sprinkler_timer_programs.

When I get some time I will see if I can work it out.