I’m trying to correctly add a cover/blinds device to ZHA. Position related attributes and commands work, but tilt doesn’t.
What’s weird about this is that I can query the current tilt position without problems using the Zigbee Clusters GUI. The attribute current_position_tilt_percentage (0x0009) in the cluster WindowCovering (0x0102 in endpoint 6) returns the value. So the device seems to report it correctly, but ZHA isn’t using it.
I’ve tried adding the following to configuration.yaml, but all it does is change the icon of the entities.
homeassistant:
# Customize all entities in a domain
customize_domain:
cover:
device_class: blind
I’d offer to implement this myself, but since I know neither Python nor the HA code base, and don’t have a second Zigbee USB stick to debug it, that would be very time consuming or maybe not even possible for me
But if anyone is willing to implement it I’d be happy to help with testing!
Would this really be the correct place? Zigpy already supports tilt for covers (I can see and read the attributes in the Zigbee cluster on the device page). It’s just ZHA that is missing functionality.
Thanks to the documentation of zha-toolkit I now figured out that I don’t even need zha-toolkit to set the tilt position. (Btw, I would have figured this out way earlier if home-assistant/frontend#10633 would have been fixed already.)
The following script works:
alias: Set cover tilt position
mode: single
icon: mdi:boom-gate-up
fields:
entity:
name: Entity
required: true
selector:
entity:
domain: cover
value:
name: Value
required: true
selector:
number:
min: 0
max: 100
sequence:
- service: zha.issue_zigbee_cluster_command
data:
ieee: '{{ (device_attr(entity, "identifiers") | list).0.1 }}'
endpoint_id: 6
cluster_id: 258
command: 8
command_type: server
args:
- '{{ 100 - value }}'
(Getting the IEEE would be easier/nicer with zha-toolkit, but that’s fine for me now.)
Endpoint, cluster and command ids are the ones from the Zigbee standard, so nothing device or vendor specific is needed. Zigpy also already supports those as a go_to_tilt_percentage command: zigpy/closures.py at 0c4b9a8a25c5eef5b008d66c2e56aae3f8d5e769 · zigpy/zigpy · GitHub
It’s just ZHA which is not using the functionality provided by Zigpy.
I’ll check how to use zha-toolkit to get the current tilt position as an attribute later.
For that you can use attr_read, define the state_id and possibly the state_attr if you want to keep multiple values in a single state. On every read, the state_id(/state_attr) will be updated and you can use that like any other state.
You could also add that to your sequence : read the attribute after sending the command (unless you can have the device report the attribute value).
P.S.: zha-toolkit can also about not using it I am happy to see that this piece in the documentation was actually useful to somebody.
Is it safe to use attr_read to create an additional property in the existing state/entity of the cover device? Or should I use it to create a new state?