Possible to send cluster command with zigbee2mqtt via automation?

Hello, is it possible to make an automation for specific devices to update the time of a zigbee device? I have many danfoss ally trv´s which i want to set the actual time once a month via an automation. I found a topic where someone did it via zha, which looks like this:

trv_update_timestamp:
alias: Update time for single TRV
sequence:

  • service: zha.set_zigbee_cluster_attribute
    data:
    ieee: ‘{{ieee}}’
    endpoint_id: 1
    cluster_id: 10
    attribute: 0
    cluster_type: in
    value: ‘{{(as_timestamp(utcnow()) - as_timestamp(“2000-01-01 00:00:00”)) | int()}}’
    mode: single

see: Danfoss Ally and weekly schedule/time issues - Hardware - Home Assistant Community (home-assistant.io)

What i want to achieve is, read the time of device and write the actual time to the specific trv.

->Read result of ‘genTime’: {“time”:733650766}
read (device ieee) endpoint=1, cluster= genTime, Attribute= time
2023-04-01 09:52:49Read result of 'genTime': {"time":733650766}

write (device ieee) endpoint=1, cluster= genTime, Attribute= time
2023-04-01 09:54:09Wrote '{"time":733650766}' to 'genTime'

I already found a topic at github, where someone else asked what i want to achieve, a long time ago. Has this ever been implemented or is it somehow possible?

Feature request: send cluster commands · Issue #3486 · Koenkk/zigbee2mqtt · GitHub

Hi

yes it is possible to update time on Ally TRVs and even required to provide regular updates if your are using weekly schedules. I have HA script for every TRV, but I’m using zigbee2mqtt in my network

service: mqtt.publish
data:
  topic: zigbee2mqtt/bedroom_trv/1/set
  payload: >-
    {"write":{"cluster":"genTime","options":{},"payload":{"time":{{utcnow().timestamp()|int}},"dstEnd":{{state_attr('input_datetime.dst_end','timestamp')|int}},"dstStart":{{state_attr('input_datetime.dst_start','timestamp')|int}},"timeZone":3600,"timeStatus":1}}}
alias: bedroom_trv
1 Like

Thank you very much :slight_smile: Thats what i needed. :slight_smile:

Please note that the Ally wants time starting from 1.1.2000 00:00:00 instead of normal epoch. Also as_timestamp(“2000-01-01 00:00:00”)) will return timestamp in local time instead of UTC time wanted by the Ally.

Blueprints for my Danfoss Ally automations are available here.