Skip to content

Commit

Permalink
Add debugging for devices
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr committed Jan 19, 2020
1 parent acf547e commit 2607efa
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 10 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,19 @@ The following attributes are set on `switch` entities:
| `sprinkler_type` | `string` | The configured type of sprinker. |
| `image_url` | `string` | The url to zone image |
| `started_watering_station_at` | `string` | The timestamp the zone started watering. |

# Debugging

To debug this integration and provide device integration for future improvements, please enable debugging in Home Assistant's `configuration.yaml`

```yaml
logger:
logs:
custom_components.bhyve: debug
bhyve:
username: !secret bhyve_username
password: !secret bhyve_password
packet_dump: true # Save all websocket event data to a file
conf_dir: "" # Storage directory for packet dump file. Usually not needed, defaults to hass_config_dir/.bhyve
```
12 changes: 8 additions & 4 deletions custom_components/bhyve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@

DATA_CONFIG = "config"

DEFAULT_SOCKET_MIN_RETRY = 15
DEFAULT_PACKET_DUMP = True
DEFAULT_PACKET_DUMP = False
DEFAULT_CONF_DIR = ""
DEFAULT_WATCHDOG_SECONDS = 5 * 60

CONFIG_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -108,7 +106,13 @@ async def async_update_callback(data):
)

await bhyve.login()
await bhyve.devices
devices = await bhyve.devices
for device in devices:
device["address"] = "REDACTED"
device["full_location"] = "REDACTED"
device["location"] = "REDACTED"

_LOGGER.debug("Devices: {}".format(devices))

hass.data[DOMAIN] = bhyve
except WebsocketError as err:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bhyve/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MANUFACTURER = "Orbit BHyve"

CONF_ATTRIBUTION = "Data provided by api.orbitbhyve.com"
CONF_CONF_DIR = ""
CONF_CONF_DIR = "conf_dir"
CONF_PACKET_DUMP = "packet_dump"

ATTR_LAST_DATA = "last_data"
Expand Down
1 change: 0 additions & 1 deletion custom_components/bhyve/pybhyve/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async def _refresh_devices(self):
for device in self._devices:
deviceName = device.get("name")
deviceType = device.get("type")
_LOGGER.info("Found device: {} [{}]".format(deviceType, deviceName))

self._last_poll = now

Expand Down
93 changes: 89 additions & 4 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# bhyve-home-assistant

BHyve component for [Home Assistant](https://www.home-assistant.io/).
Orbit BHyve component for [Home Assistant](https://www.home-assistant.io/).

If this integration has been useful to you, please consider chipping in and buying me a coffee!

<a href="https://www.buymeacoffee.com/sebr" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee"></a>

## Supported Entities
* `sensor` for measuring battery levels of `sprinkler_timer` devices
* `binary_sensor` for tracking rain/weather delays
* `switch` for turning a zone on/off

- `sensor` for measuring battery levels of `sprinkler_timer` devices
- `binary_sensor` for tracking rain/weather delays
- `switch` for turning a zone on/off

## Installation

Recommended installation is via HACS.

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)

## Configuration

Expand All @@ -23,3 +34,77 @@ binary_sensor:
switch:
- platform: bhyve
```
## Sensor Entities
`sensor` entities are automatically created for any device which has a battery level to report.

## Binary Sensor Entities

A **Rain Delay** `binary sensor` will be created for each discovered `sprinkler_timer` device. This entity will be **on** whenever BHyve reports that a device's watering schedule will be delayed due to weather conditions.

### Rain Delay Attributes

The following attributes are set on `binary_sensor.rain_delay_*` entities, if the sensor is on:

| Attribute | Type | Notes |
| -------------- | -------- | ----------------------------------------------------------------------------------------- |
| `cause` | `string` | Why a delay was put in place. Values seen: `auto`. May be empty. |
| `delay` | `number` | The number of hours the delay is in place. NB: This is hours from `started_at` attribute. |
| `weather_type` | `string` | The reported cause of the weather delay. Values seen: `wind`, `rain`. May be empty. |
| `started_at` | `string` | The timestamp the delay was put in place. |

### Rain Delay Template Sensors

It is possible to create template sensors from these attributes. Here are two examples which provide a sensor to report:

1. When the current rain delay for a device is ending
2. The number of hours remaining on the current rain delay

```yaml
sensor:
- platform: template
sensors:
rain_delay_lawn_finishing:
friendly_name: "Rain Delay Lawn Finishing"
value_template: "{{(as_timestamp(state_attr('binary_sensor.rain_delay_lawn', 'started_at')) + state_attr('binary_sensor.rain_delay_lawn', 'delay') * 3600) | timestamp_local }}"
rain_delay_lawn_remaining:
friendly_name: "Rain Delay Lawn Remaining"
unit_of_measurement: "h"
value_template: "{{((as_timestamp(state_attr('binary_sensor.rain_delay_lawn', 'started_at')) + state_attr('binary_sensor.rain_delay_lawn', 'delay') * 3600 - as_timestamp(now())) / 3600) | round(0) }}"
```

## Switch Entities

A `switch` entity is created for each zones of a `sprinkler_timer` device. This switch enables starting/stopping irrigation of a zone.

Turning on the switch will enable watering of the zone for the amount of time configured in the BHyve app.

### Switch Attributes

The following attributes are set on `switch` entities:

| Attribute | Type | Notes |
| ----------------------------- | --------- | -------------------------------------------------------------------- |
| `manual_preset_runtime` | `number` | The number of seconds to run zone watering when switch is turned on. |
| `smart_watering_enabled` | `boolean` | True if the zone has a smart water schedule enabled. |
| `sprinkler_type` | `string` | The configured type of sprinker. |
| `image_url` | `string` | The url to zone image |
| `started_watering_station_at` | `string` | The timestamp the zone started watering. |

# Debugging

To debug this integration and provide device integration for future improvements, please enable debugging in Home Assistant's `configuration.yaml`

```yaml
logger:
logs:
custom_components.bhyve: debug
bhyve:
username: !secret bhyve_username
password: !secret bhyve_password
packet_dump: true # Save all websocket event data to a file
conf_dir: "" # Storage directory for packet dump file. Usually not needed, defaults to hass_config_dir/.bhyve
```

0 comments on commit 2607efa

Please sign in to comment.