bhyve-home-assistant icon indicating copy to clipboard operation
bhyve-home-assistant copied to clipboard

Add soil moisture % sensor

Open sethhere04 opened this issue 2 years ago • 9 comments

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

sethhere04 avatar May 18 '22 22:05 sethhere04

@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.

sebr avatar May 19 '22 00:05 sebr

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.

sethhere04 avatar May 19 '22 01:05 sethhere04

I came here to ask the exact same question!

AnthonyBe avatar May 19 '22 15:05 AnthonyBe

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

sebr avatar May 22 '22 01:05 sebr

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

allistermaguire avatar May 22 '22 07:05 allistermaguire

+1 on this feature.

doe81 avatar Oct 05 '22 13:10 doe81

+1

kdeyev avatar Aug 21 '23 04:08 kdeyev

@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?

kdeyev avatar Aug 26 '23 15:08 kdeyev

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.

allistermaguire avatar Sep 04 '23 23:09 allistermaguire