Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aneisch committed Oct 28, 2023
1 parent 7c96b72 commit 08e876e
Show file tree
Hide file tree
Showing 23 changed files with 284 additions and 62 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://github.com/aneisch/home-assistant-config/actions/workflows/check-ha-release-compatibility.yml/badge.svg)](https://github.com/aneisch/home-assistant-config/actions)
[![GitHub last commit](https://img.shields.io/github/last-commit/aneisch/home-assistant-config)](https://github.com/aneisch/home-assistant-config/commits/master)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/aneisch/home-assistant-config)](https://github.com/aneisch/home-assistant-config/graphs/commit-activity)
[![HA Version](https://img.shields.io/badge/Running%20Home%20Assistant-2023.10.4%20(Latest)-brightgreen)](https://github.com/home-assistant/home-assistant/releases/latest)
[![HA Version](https://img.shields.io/badge/Running%20Home%20Assistant-2023.10.5%20(Latest)-brightgreen)](https://github.com/home-assistant/home-assistant/releases/latest)
<br><a href="https://www.buymeacoffee.com/aneisch" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-black.png" width="150px" height="35px" alt="Buy Me A Coffee" style="height: 35px !important;width: 150px !important;" ></a>


Expand Down Expand Up @@ -56,7 +56,7 @@ Also using Grafana/Influx for graphing, both running in Docker containers on NUC
Description | value
-- | --
Lines of ESPHome YAML | 2467
Lines of Home Assistant YAML | 8149
Lines of Home Assistant YAML | 8142
[Integrations](https://www.home-assistant.io/integrations/) in use | 52
Zigbee devices in [`zha`](https://www.home-assistant.io/integrations/zha/) | 26
Z-Wave devices in [`zwave_js`](https://www.home-assistant.io/integrations/zwave_js/) | 37
Expand All @@ -80,7 +80,7 @@ Entities in the [`input_datetime`](https://www.home-assistant.io/components/inpu
Entities in the [`input_number`](https://www.home-assistant.io/components/input_number) domain | 4
Entities in the [`input_select`](https://www.home-assistant.io/components/input_select) domain | 19
Entities in the [`input_text`](https://www.home-assistant.io/components/input_text) domain | 8
Entities in the [`light`](https://www.home-assistant.io/components/light) domain | 38
Entities in the [`light`](https://www.home-assistant.io/components/light) domain | 39
Entities in the [`lock`](https://www.home-assistant.io/components/lock) domain | 3
Entities in the [`media_player`](https://www.home-assistant.io/components/media_player) domain | 12
Entities in the [`number`](https://www.home-assistant.io/components/number) domain | 5
Expand All @@ -100,7 +100,7 @@ Entities in the [`update`](https://www.home-assistant.io/components/update) doma
Entities in the [`vacuum`](https://www.home-assistant.io/components/vacuum) domain | 1
Entities in the [`weather`](https://www.home-assistant.io/components/weather) domain | 2
Entities in the [`zone`](https://www.home-assistant.io/components/zone) domain | 6
**Total state objects** | **1067**
**Total state objects** | **1068**
## The HACS integrations/plugins that I use:
**Appdaemon**:<br>
[aneisch/follow_me_appdaemon](https://github.com/aneisch/follow_me_appdaemon)<br>
Expand Down
29 changes: 9 additions & 20 deletions automations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,6 @@
- service: homeassistant.turn_on
entity_id: switch.docker_watchtower


- alias: "Update Water Utilities"
id: "update_water_utilities"
trigger:
Expand All @@ -690,18 +689,6 @@
- service: python_script.add_water_cost_attribute
data:
meter_entity: sensor.water_usage
- if: "{{ trigger.id == 'midnight' }}"
then:
- service: python_script.utility_meter_reset
data:
meter_entity: sensor.water_usage
cycle_reset_entity_id: sensor.electric_utilities_summary
- if: "{{ trigger.id == 'midnight' }}"
then:
- service: python_script.utility_meter_reset
data:
meter_entity: sensor.electricity_usage
cycle_reset_entity_id: sensor.electric_utilities_summary

- alias: "Update Utility Costs"
id: "update_utility_costs"
Expand All @@ -721,17 +708,16 @@
id: "reset_utility_meters"
trigger:
- platform: time
id: midnight
at: "00:00:00"
action:
- service: python_script.utility_meter_reset
data:
meter_entity: sensor.water_usage
cycle_reset_entity_id: sensor.electric_utilities_summary
cycle_reset_entity_id: sensor.utilities_cycle_end
- service: python_script.utility_meter_reset
data:
meter_entity: sensor.electricity_usage
cycle_reset_entity_id: sensor.electric_utilities_summary
cycle_reset_entity_id: sensor.utilities_cycle_end

# Legacy, remove later
- alias: "Update Electric Utilities Cost"
Expand Down Expand Up @@ -1080,10 +1066,13 @@
from:
- "unknown"
- "unavailable"
- platform: numeric_state
entity_id: sensor.neighbor_5in1_rain_last_1_hour
above: 0.00
below: 0.03
- "0.0"
- "0.00"
- "0"
# - platform: numeric_state
# entity_id: sensor.neighbor_5in1_rain_last_1_hour
# above: 0.00
# below: 0.03
action:
- if:
# Ensure new state is a float > 0.00
Expand Down
14 changes: 8 additions & 6 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ homeassistant:
allowlist_external_urls:
- "http://localhost:8123/api/frigate/notifications"
media_dirs:
audio: audio/
audio: media/audio/
video: media/video/
images: media/images/

alexa: !include alexa.yaml

Expand Down Expand Up @@ -178,11 +180,11 @@ light:
version: 5
port: 8899
groups:
# big bulbs
#- number: 1
# type: rgbw
# name: Garage
# fade: on
#big bulbs
- number: 1
type: rgbw
name: Front Porch Halloween
fade: on
- number: 2
type: rgbw
name: plant_light_corner
Expand Down
10 changes: 6 additions & 4 deletions custom_components/bhyve/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def async_setup_entry(


class BHyveFloodSensor(BHyveDeviceEntity):
"""Define a BHyve sensor."""
"""Define a BHyve flood sensor."""

def __init__(self, hass, bhyve, device):
"""Initialize the sensor."""
Expand Down Expand Up @@ -91,8 +91,9 @@ def _on_ws_data(self, data):
def _should_handle_event(self, event_name, data):
return event_name in [EVENT_FS_ALARM]


class BHyveTemperatureBinarySensor(BHyveDeviceEntity):
"""Define a BHyve temperature sensor."""

def __init__(self, hass, bhyve, device):
name = "{} temperature alert".format(device.get("name"))
Expand All @@ -102,11 +103,11 @@ def _setup(self, device):
self._available = device.get("is_connected", False)
self._state = self._parse_status(device.get("status", {}))
self._attrs = device.get("temp_alarm_thresholds")

def _parse_status(self, status):
"""Convert BHyve alarm status to entity value."""
return "on" if "alarm" in status.get("temp_alarm_status") else "off"

@property
def state(self):
"""Return the state of the entity."""
Expand All @@ -119,6 +120,7 @@ def unique_id(self):

@property
def is_on(self):
"""Reports state of the temperature sensor."""
return self._state == "on"

def _on_ws_data(self, data):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/bhyve/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ async def async_step_import(self, config):
devices = [str(d["id"]) for d in self.devices if d["type"] != DEVICE_BRIDGE]

return await self.async_step_device(user_input={CONF_DEVICES: devices})
else:
return self.async_abort(reason="cannot_connect")

return self.async_abort(reason="cannot_connect")

@staticmethod
@callback
Expand Down
3 changes: 2 additions & 1 deletion custom_components/bhyve/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
DEVICE_SPRINKLER = "sprinkler_timer"
DEVICE_FLOOD = "flood_sensor"

EVENT_BATTERY_STATUS = "battery_status"
EVENT_CHANGE_MODE = "change_mode"
EVENT_FS_ALARM = "fs_status_update"
EVENT_DEVICE_IDLE = "device_idle"
EVENT_FS_ALARM = "fs_status_update"
EVENT_PROGRAM_CHANGED = "program_changed"
EVENT_RAIN_DELAY = "rain_delay"
EVENT_SET_MANUAL_PRESET_TIME = "set_manual_preset_runtime"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bhyve/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://github.com/sebr/bhyve-home-assistant/blob/main/README.md",
"iot_class": "cloud_push",
"requirements": [],
"version": "3.2.0"
"version": "3.2.1"
}
51 changes: 47 additions & 4 deletions custom_components/bhyve/sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Support for Orbit BHyve sensors."""
import logging
from datetime import timedelta

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_BATTERY_LEVEL
Expand All @@ -16,6 +17,7 @@
DEVICE_FLOOD,
DEVICE_SPRINKLER,
DOMAIN,
EVENT_BATTERY_STATUS,
EVENT_CHANGE_MODE,
EVENT_DEVICE_IDLE,
EVENT_FS_ALARM,
Expand All @@ -35,6 +37,8 @@
ATTR_START_TIME = "start_time"
ATTR_STATUS = "status"

SCAN_INTERVAL = timedelta(minutes=5)


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
Expand Down Expand Up @@ -86,8 +90,11 @@ def _setup(self, device):

battery = device.get("battery")

_LOGGER.debug("%s battery: %s", self._device_name, battery)

if battery is not None:
battery_level = battery.get("percent", 0)
battery_level = self.parse_battery_level(battery)

self._state = battery_level
self._attrs[ATTR_BATTERY_LEVEL] = battery_level

Expand Down Expand Up @@ -115,6 +122,11 @@ def should_poll(self):
"""Enable polling."""
return True

@property
def scan_interval(self):
"""Return the scan interval."""
return SCAN_INTERVAL

@property
def unique_id(self):
"""Return a unique, unchanging string that represents this sensor."""
Expand All @@ -126,14 +138,45 @@ def entity_category(self):
return EntityCategory.DIAGNOSTIC

def _should_handle_event(self, event_name, data):
return event_name in [EVENT_CHANGE_MODE]
return event_name in [EVENT_BATTERY_STATUS, EVENT_CHANGE_MODE]

def _on_ws_data(self, data):
# {'event': 'battery_status', 'mv': 3311, 'charging': false ... }
#
event = data.get("event")
if event in (EVENT_BATTERY_STATUS):
battery_level = self.parse_battery_level(event)

self._state = battery_level
self._attrs[ATTR_BATTERY_LEVEL] = battery_level

async def async_update(self):
"""Retrieve latest state."""
self._ws_unprocessed_events[:] = [] # We don't care about these

super().async_update()
await self._refetch_device()

@staticmethod
def parse_battery_level(battery_data):
"""
Parses the battery level data and returns the battery level as a percentage.
If the 'percent' attribute is present in the battery data, it is used as the battery level.
Otherwise, if the 'mv' attribute is present, the battery level is calculated as a percentage
based on the millivolts, assuming that 2x1.5V AA batteries are used. Note that AA batteries can
range from 1.2V to 1.7V depending on their chemistry, so the calculation may not be accurate
for all types of batteries. YMMV ¯\_(ツ)_/¯
Args:
battery_data (dict): A dictionary containing the battery data.
Returns:
float: The battery level as a percentage.
"""
battery_level = battery_data.get("percent", 0)
if "mv" in battery_data:
battery_level = min(battery_data.get("mv", 0) / 3000 * 100, 100)
return battery_level


class BHyveZoneHistorySensor(BHyveDeviceEntity):
"""Define a BHyve sensor."""
Expand Down
2 changes: 0 additions & 2 deletions custom_components/bhyve/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Describes the format for available virtual services

enable_rain_delay:
description: Enable rain delay for a zone
fields:
Expand Down
88 changes: 88 additions & 0 deletions custom_components/bhyve/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,93 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"services": {
"enable_rain_delay": {
"name": "Enable rain delay",
"description": "Enable rain delay for a zone",
"fields": {
"entity_id": {
"name": "Zone switch",
"description": "The switch to enable rain delay for"
},
"hours": {
"name": "Hours",
"description": "The number of hours to enable rain delay for"
}
}
},
"disable_rain_delay": {
"name": "Disable rain delay",
"description": "Disable rain delay for a zone",
"fields": {
"entity_id": {
"name": "Zone switch",
"description": "The switch to disable rain delay for"
}
}
},
"start_watering": {
"name": "Start watering",
"description": "Start watering a zone",
"fields": {
"entity_id": {
"name": "Zone switch",
"description": "The switch to start watering"
},
"minutes": {
"name": "Minutes",
"description": "The number of minutes to water for"
}
}
},
"stop_watering": {
"name": "Stop watering",
"description": "Stop watering a zone",
"fields": {
"entity_id": {
"name": "Zone switch",
"description": "The switch to stop watering"
}
}
},
"set_manual_preset_runtime": {
"name": "Set manual preset runtime",
"description": "Set the manual preset runtime for a device entity",
"fields": {
"entity_id": {
"name": "Zone switch",
"description": "The switch to set the manual preset runtime for"
},
"minutes": {
"name": "Minutes",
"description": "The number of minutes to set the manual preset runtime to"
}
}
},
"set_smart_watering_soil_moisture": {
"name": "Set smart watering soil moisture",
"description": "Set the smart watering soil moisture level for a zone",
"fields": {
"entity_id": {
"name": "Zone switch",
"description": "The switch to set the smart watering soil moisture for"
},
"percentage": {
"name": "Percentage",
"description": "Moisture level between 0 - 100 (percent)"
}
}
},
"start_program": {
"name": "Start program",
"description": "Begin watering a program",
"fields": {
"entity_id": {
"name": "Program switch",
"description": "The program to start"
}
}
}
}
}
Loading

0 comments on commit 08e876e

Please sign in to comment.