Skip to content

Commit

Permalink
Merge pull request #269 from asantaga/dev
Browse files Browse the repository at this point in the history
v3.1.0
  • Loading branch information
msp1974 authored Jul 9, 2022
2 parents 1944f11 + 1ba2447 commit 60610a3
Show file tree
Hide file tree
Showing 16 changed files with 3,402 additions and 354 deletions.
82 changes: 36 additions & 46 deletions Readme.Md → README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Wiser Home Assistant Integration v3.0.24
# Wiser Home Assistant Integration v3.1.0

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

This repository contains a Home Assistant component + platforms, for the awesome Drayton Wiser Heating solution. It also supports the European version of the Wiser Hub under the Schneider Electric brand, including support for lights and blinds.

Expand All @@ -7,16 +9,20 @@ For the latest version of the Wiser Home Assistant Platform please use the maste
For more information checkout the AMAZING community thread available on https://community.home-assistant.io/t/drayton-wiser-home-assistant-integration/80965

---
## What's New?
- The Wiser Schedule Card to allow you add, edit, rename, delete and assign schedules to rooms or devices via the HA UI. See [Schedule Card](#schedule-card) for how to setup and use.

## Contents

- [Minimum Requirements](#minimum-requirements)
- [Updating to v3.0 from v2.x](#updating-to-v30-from-v2.x---important-please-read)
- [Updating to v3.x from v2.x](#updating-to-v30-from-v2.x---important-please-read)
- [Issues & Questions](#issues-and-questions)
- [Functionality of this Integration](#functionality)
- [Installing](#code-installation)
- [Configuration](#configuration)
- [Managing Schedules with Home Assistant](#managing-schedules-with-home-assistant)
- [Network Topology](#network-topology)
- [Schedule Card](#schedule-card)
- [Network Map](#network-map)
- [Battery Values](#battery-values)
- [Community and Recipes](#community)
Expand All @@ -26,11 +32,9 @@ For more information checkout the AMAZING community thread available on https://

## Minimum Requirements

Requires a minimum of HA 2021.12. This is needed to support the new button functionality and changes to config flow.
Requires the new WiserHeatAPIv2 api.
Requires a minimum of HA 2022.06.


## Updating to v3.0 from v2.x - IMPORTANT PLEASE READ!
## Updating to v3.x from v2.x - IMPORTANT PLEASE READ!

Some of the great new functionality below has only been possible by making some major changes to the integration code and how HA entities are registered. As such, when upgrading a number of existing entities in v2 will be replaced with new ones and the old ones will show unavailable.

Expand Down Expand Up @@ -68,8 +72,7 @@ Mark & Angelo
- Support for hub discovery and UI config. No YAML editing.

- Support for multiple hubs
- Support for Wiser Hub, iTRVs, Roomstats, Heating Actuators and SmartPlugs
- Basic sensor support for Dimmable Lights and Shutters
- Support for Wiser Hub, iTRVs, Roomstats, Heating Actuators, SmartPlugs, Lights and Blinds

- **Hub (System) Device**
- Various switches to control hub settings (Away Mode, Comfort Mode, Daylight Saving, Eco Mode, Valve Protection)
Expand Down Expand Up @@ -112,9 +115,6 @@ Mark & Angelo
- Selector to set mode (Auto, Manual) for Smart Plug
- Many attributes available

- **Network Map Sensor**
- Sensor for use with Zigbee2mqtt Networkmap Card by @azuwis - see XXXX for how to setup

- **Moments**
- Buttons to activate Moments configured in the Wiser App

Expand All @@ -129,7 +129,8 @@ Mark & Angelo
- Service `remove_orphaned_entries`: Provides ability to remove HA devices for rooms/devices that have been removed from your hub. Must have no entities.
- Service `output_hub_json`: Provides ability to output hub json to 3 anonymised files to enable easier debugging


- **UI Cards**
- Schedule Card to add, edit, delete and rename schedules
## Sample Images

![](docs/screenshot.PNG)
Expand All @@ -146,8 +147,6 @@ Mark & Angelo

![](docs/heatingactuator.PNG)

![](docs/networkmap.png)


# Code Installation

Expand Down Expand Up @@ -453,7 +452,22 @@ In order to create these files do the following:
4) Select Call Service
5) This will output 3 files - domain.json, schedule.json, network.json in a directory wiser_data in your config directory. These can be uploaded to an issue on github.

## Schedule Card

This is our first venture into creating UI components for Home Assistant. We have done a lot of testing but there maybe some scenarios we haven't thought of that could enhibit unexpected behaviour. Rest assured however, the worst that can happen is a deleted schedule that you will have to recreate.

So, it has been on our request list since early 2021 to be able to manage schedules via HA. Well, as HA lacks any inbuilt way to do this, we have had to build our own. I would like to give a shout out to @neilsfaber who writes the amazing scheduler-card integration and card for HA where we have used his code to learn how to do this, and copied some of his ideas/code.

It is very simple to use/add the card. If you go to add a card to your dashboard, you will now see the Wiser Schedule Card in the list. Just add like any other card.

Instead of lots of words about how to use this card, we thought best to do a short video which may lack Tarantino quality directorship but should get the point across!


![](docs/schedule-card.PNG)

[Video](https://www.loom.com/share/6c85291deee94d709f36515be8fc1763)

We hope you enjoy it and find it useful in managing your Wiser environment via HA.
## Network Topology

With V1.9 for TRVs you can now determine if the TRV is connected to the heathub directly or via a smartplug repeater.
Expand All @@ -470,38 +484,7 @@ Each TRV sensor now has three special network related attributes

## Network Map

From v3.0.24, you can now use the zigbee2mqtt-networkmap card from @azuwis to display an image of your Wiser Zigbee network. The below instructions will help you set it up.
1) Firstly, install the zigbee2mqtt-networkmap card using HACS
2) Create a new card in lovelace with the following yaml
```yaml
type: custom:zigbee2mqtt-networkmap
entity: sensor.wiser_zigbee_network_map
node_size: 24
font_size: 10
link_width: 2
height: 500
force: 5000
css: |
.card-actions mwc-button {visibility: hidden}
:host {
--zigbee2mqtt-networkmap-node-fill-color: var(--ha-card-background, var(--card-background-color, white));
--zigbee2mqtt-networkmap-node-pinned-color:var(--primary-color);
--zigbee2mqtt-networkmap-link-color: var(--primary-color);
--zigbee2mqtt-networkmap-hover-color: var(--primary-color);
--zigbee2mqtt-networkmap-link-selected-color:var(--primary-color);
--zigbee2mqtt-networkmap-label-color: var(--primary-text-color);
--zigbee2mqtt-networkmap-arrow-color: var(--primary-color);
--zigbee2mqtt-networkmap-node-coordinator-color: var(--label-badge-red);
--zigbee2mqtt-networkmap-node-router-color: var(--label-badge-green);
}
```
3) Tweak the settings and css to suit how you want it to look.

![](docs/networkmap.png)

***NOTES***
1) As this card is designed to work with zigbee2mqtt, we are using css in the card yaml to hide the refresh button. This is advisable as a) it doesn't do anything and b) if you don't have mqtt installed it will error.
This was removed from 3.0.24 just before release as it caused some spamming of the HA logs. It will return in 3.1.x as a dedicated Wiser Zigbee network map card.


## Battery Values
Expand Down Expand Up @@ -544,6 +527,13 @@ And many many more, please see github pull requests for more info
Moving forward (post 1.9) there will be two primary branches, `master` and `dev` . Master will be the primary "production" branch and "dev" will be the branch used for development. Other branches will likely exist where we build code into and then merge into dev, which in turn gets merged into master when all is good and dandy.

# Change log
- 3.1.0
* Bump api to 0.0.37
* Fix for battery voltages over 3v show 0%
* Added update delay after sending light command to allow time for hub to update new values before reading
* Added websockets functions to support schedule card
* Addded schedule card to managed schedules
* Fixed deprecation functions warning for number entity
- 3.0.24
* Bump api to 0.0.32
* Add shutter, light and dimable light support - thanks @LGO44
Expand Down
56 changes: 53 additions & 3 deletions custom_components/wiser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import asyncio
from datetime import timedelta, datetime
import logging
import json
import voluptuous as vol
from wiserHeatAPIv2.wiserhub import (
TEMP_MINIMUM,
Expand Down Expand Up @@ -39,8 +40,12 @@
)
from homeassistant.helpers.dispatcher import dispatcher_send
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.loader import Integration, async_get_integration
from homeassistant.util import Throttle

from .websockets import async_register_websockets
from .frontend import locate_dir

from .const import (
CONF_MOMENTS,
CONF_SETPOINT_MODE,
Expand All @@ -55,8 +60,10 @@
DEFAULT_SCAN_INTERVAL,
DOMAIN,
MANUFACTURER,
SCHEDULE_CARD_FILENAME,
UPDATE_LISTENER,
UPDATE_TRACK,
URL_BASE,
WISER_PLATFORMS,
WISER_SERVICES
)
Expand Down Expand Up @@ -194,6 +201,8 @@ async def async_setup_entry(hass, config_entry):
hass.config_entries.async_forward_entry_setup(config_entry, platform)
)

await async_register_websockets(hass, data)

# Initialise global services
def get_entity_from_entity_id(entity: str):
"""Get wiser entity from entity_id"""
Expand Down Expand Up @@ -378,6 +387,18 @@ def output_hub_json(service):
# Add hub as device
await data.async_update_device_registry()

# Register custom cards
url = f"{URL_BASE}/{SCHEDULE_CARD_FILENAME}"
hass.http.register_static_path(
URL_BASE,
hass.config.path("custom_components/wiser/frontend"),
cache_headers=False
)
resource_loaded = [res["url"] for res in hass.data['lovelace']["resources"].async_items() if res["url"] == url]
if not resource_loaded:
# Custom card - need to remove on uninstall!
resource_id = await hass.data['lovelace']["resources"].async_create_item({"res_type":"module", "url":url})

_LOGGER.info("Wiser Component Setup Completed")

return True
Expand All @@ -396,6 +417,12 @@ async def async_unload_entry(hass, config_entry):
:param config_entry:
:return:
"""
# Unload lovelace module resource
url = f"{URL_BASE}/{SCHEDULE_CARD_FILENAME}"
wiser_resources = [resource for resource in hass.data['lovelace']["resources"].async_items() if resource["url"] == url]
for resource in wiser_resources:
await hass.data['lovelace']["resources"].async_delete_item(resource.get("id"))

# Deregister services
_LOGGER.debug("Unregister Wiser Services")
hass.services.async_remove(DOMAIN, SERVICE_REMOVE_ORPHANED_ENTRIES)
Expand Down Expand Up @@ -466,11 +493,13 @@ async def async_update(self, no_throttle: bool = False):
try:
result = await self._hass.async_add_executor_job(self.wiserhub.read_hub_data)
if result:
_LOGGER.debug(f"Wiser Hub data updated - {self.wiserhub.system.name}")
_LOGGER.info(f"Wiser Hub data updated - {self.wiserhub.system.name}")
# Send update notice to all components to update
self.last_update_time = datetime.now()
self.last_update_status = "Success"
dispatcher_send(self._hass, f"{self.wiserhub.system.name}-HubUpdateMessage")
# Fire event on successfull update
dispatcher_send(self._hass,"wiser_update_received")
return True

_LOGGER.error(f"Unable to update from Wiser hub - {self.wiserhub.system.name}")
Expand Down Expand Up @@ -556,5 +585,26 @@ async def async_output_hub_json(self, entry_id, wiser_hub_id: str):
wiserhub.output_raw_hub_data, endpoint, f"{endpoint}-{datetime.now().strftime('%Y%m%d-%H%M%S')}", self._hass.config.config_dir
):
_LOGGER.info(f"Written hub {endpoint} data to the wiser_data subdirectory in your config directory")



def _remove_schedule_elements(self, schedule_data: dict) -> dict:
remove_list = ["Name", "Description", "Type"]
for item in remove_list:
if item in schedule_data:
del schedule_data[item]
return schedule_data

def async_get_schedules(self):
"""fetch a list of schedules (websocket API hook)"""
schedules = []
for schedule in self.wiserhub.schedules.all:
schedules.append(
{
"id": schedule.id,
"name": schedule.name,
"type": schedule.schedule_type,
"level_type": schedule.schedule_level_type if hasattr(schedule, 'schedule_level_type') else None,
"schedule": self._remove_schedule_elements(schedule._convert_from_wiser_schedule(schedule.schedule_data))
}
)

return schedules
4 changes: 3 additions & 1 deletion custom_components/wiser/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"""
DOMAIN = "wiser"
DATA_WISER_CONFIG = "wiser_config"
URL_BASE = "/wiser"
SCHEDULE_CARD_FILENAME = "wiser-schedule-card.js"

VERSION = "3.0.24"
VERSION = "3.1.0"
WISER_PLATFORMS = ["climate", "sensor", "switch", "select", "button", "number", "light", "cover"]
DATA = "data"
UPDATE_TRACK = "update_track"
Expand Down
Loading

0 comments on commit 60610a3

Please sign in to comment.