Phoscon Hive no Battery Status

I have 4 Phoscon Hive Battery lights on my Zigbee ZHA network.

Hive Overview (phoscon.de)

While I can control the lights without any issues and the devices are running the latest firmware, the battery status does not display.

However, I can read the battery status using the Cluster command and get a correct value from 0 to 200 for battery_percentage_remaining (id: 0x0021).
Interestingly, the lights are showing as main-powered instead of battery-powered.

Does anyone have any ideas on how to solve this issue?

Device Signature:

{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.MainsPowered|RxOnWhenIdle|AllocateAddress: 140>, manufacturer_code=4405, maximum_buffer_size=82, maximum_incoming_transfer_size=82, server_mask=11264, maximum_outgoing_transfer_size=82, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x010d",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0004",
        "0x0005",
        "0x0006",
        "0x0008",
        "0x0300"
      ],
      "output_clusters": [
        "0x0019"
      ]
    },
    "242": {
      "profile_id": "0xa1e0",
      "device_type": "0x0061",
      "input_clusters": [],
      "output_clusters": [
        "0x0021"
      ]
    }
  },
  "manufacturer": "Phoscon",
  "model": "Hive",
  "class": "zigpy.device.Device"
}

Hi Alex,

I also couldn’t create a sensor with the battery value of the hive via ZHA.
Seems, the function zha.read_zigbee_cluster_attribute isn’t implemented yet (see also topics here in the forum and on Github)

A possible solution is to install the HACS-integration zha-toolkit with its function zha_toolkit.attr_read.

An automation reads the battery level periodically, writes the value into a helper (input_number), which is used as base for the battery-sensor (helper/template-sensor):

  • Add helper “number” (range 0-200): input_number.hive_battery_measure
  • Add helper “template” (sensor): sensor.hive_battery
    with state template:
{{ (states('input_number.hive_battery_measure') | int / 2 ) | round(0) }}
  • Add automation:
alias: Hive Battery
description: ""
trigger:
  - platform: time_pattern
    hours: /1
condition:
  - alias: Test if available
    condition: not
    conditions:
      - condition: or
        conditions:
          - condition: state
            entity_id: light.hive
            state: unknown
          - condition: state
            entity_id: light.hive
            state: unavailable
action:
  - service: zha_toolkit.attr_read
    data:
      ieee: light.hive
      endpoint: 1
      cluster: 1
      attribute: 33
      state_id: input_number.hive_battery_measure
mode: single

The automation reads the battery value once an hour, what seems enough for me and doesn’t drain the battery too much. To prevent errors, a condition checks whether the lamp is (not) available. The attribute 33 is the decimal equivalent for hex 0x0021, the id of Hives cluster attribute battery_percentage_remaining.
In the template, the measured battery value is converted into an integer percentage value (division by 2).
Apparently the battery level changes in steps of 20, the sensor accordingly by 10%.

1 Like

Thanks for your feedback … will directly try.

Hello 7knips,

thanks your solution is working. I have now all the battery states for my hive lamps.
Grate workaround and solution!

Currently I am in contact with phoscon to get this topic solved without the workaround.
I keep you informend.

Thanks again
:slight_smile:

Here the forum discussion with Phoscon

Hive no battery status - Dresden-Elektronik Hardware - deCONZ Community (phoscon.de)

Is it possible to over write the MACCapabilityFlags with a device spezific quirk?

Solved the topic by digging into custom quirks.
My HIVEs have now a battery status.

Oh, wow - nice work!
Seems to be a solution without extra stuff like zha-toolkit.

How did you built this custom quirk, and where is it stored to be available in home assistant?
Did you publish it anywhere, e.g. on https://github.com/zigpy/zha-device-handlers

Thanks for “digging into”

I had some interest and questions about this topic … there is a step-by-step guide including the code.

Prerequisites

  • Visual Code Server Add-on:
    It is recommended to install and use the Visual Code Server add-on for editing files. This add-on provides an integrated development environment within Home Assistant, making it easier to manage your configuration files.

Step-by-Step Guide

  1. Create the Directory
    In your Home Assistant CONFIG directory, create a new folder named custom_zha_quirks.
    2.Note:* If you already have a folder for custom quirks, you can skip this step and adjust the configuration in the next step accordingly.
  2. Update the Configuration
    Open your configuration.yaml file and add the following lines to tell Home Assistant where to find your custom quirks:
zha:
  custom_quirks_path: /config/custom_zha_quirks/
  1. Initialize the Python Package
    Inside the custom_zha_quirks directory, create a file named __init__.py. This file can remain empty, but it is required to mark the directory as a Python package.
  2. Copy the Quirk Code
    Create a new file named phoscon_hive_quirk.py in the custom_zha_quirks directory and copy the following code into it:

Code phoscon_hive_quirk.py:

from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import Basic, PowerConfiguration, Identify, Groups, Scenes, OnOff, LevelControl, Ota, GreenPowerProxy
from zigpy.zcl.clusters.lighting import Color

class PhosconHive(CustomDevice):
    """Custom device representing Phoscon Hive."""

    signature = {
        "models_info": [("Phoscon", "Hive")],
        "endpoints": {
            1: {
                "profile_id": 0x0104,
                "device_type": 0x010d,
                "input_clusters": [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    OnOff.cluster_id,
                    LevelControl.cluster_id,
                    Color.cluster_id
                ],
                "output_clusters": [
                    Ota.cluster_id,
                ],
            },
            242: {
                "profile_id": 0xA1E0,
                "device_type": 0x0061,
                "input_clusters": [],
                "output_clusters": [
                    GreenPowerProxy.cluster_id,
                ],
            },
        },
    }

    replacement = {
        "endpoints": {
            1: {
                "profile_id": 0x0104,
                "device_type": 0x010d,
                "input_clusters": [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    Groups.cluster_id,
                    Scenes.cluster_id,
                    OnOff.cluster_id,
                    LevelControl.cluster_id,
                    Color.cluster_id
                ],
                "output_clusters": [
                    Ota.cluster_id,
                ],
            },
            242: {
                "profile_id": 0xA1E0,
                "device_type": 0x0061,
                "input_clusters": [],
                "output_clusters": [
                    GreenPowerProxy.cluster_id,
                ],
            },
        },
    }

    def __init__(self, *args, **kwargs):
        """Initialize the device."""
        super().__init__(*args, **kwargs)
        self.node_desc.mac_capability_flags &= ~0b00000100  # Clear the mains powered bit
  1. Restart Home Assistant
    After saving the changes, restart Home Assistant so that the new configuration is loaded and your custom quirk is applied.