zigpy / zha

Zigbee Home Automation
Apache License 2.0
18 stars 14 forks source link

Time in ZHA is UTC despite setting local time in HA #150

Closed mguaylam closed 1 month ago

mguaylam commented 1 month ago

I display the local time with my Sinopé thermostats but since HA 2024.8.0 my thermostats are displaying UTC. Seem's to happen with the decoupling of ZHA from core.

https://github.com/zigpy/zha/blob/db2bf30f7399c54d0004f06302404b139b887abc/zha/application/platforms/climate/__init__.py#L536

Hedda commented 1 month ago

FYI, more ZHA users reported this -> https://community.home-assistant.io/t/zigbee-thermostats-incorrect-time-zone/248024/

As I don't have this or any other Zigbee device that uses timezone I am wondering if the zha integration component and/ or the ZHA gateway should not automatically get and set the time zone based on what is set in the underlying host application (i.e, Home Assistant) or operating system (i.e, Home Assistant OS) and the computer that it is running on?

zha-toolkit has a feature for misc_settime for setting attributes of a Time Cluster from HA's current time and timezone:

https://github.com/mdeweerd/zha-toolkit/blob/main/README.md#misc_settime-set-attributes-of-a-time-cluster

That question about that was by the way also asked but not answered under zigpy discussions here:

Stumbled on these PRs for OpenHAB's ZigBee Binding and the com.zsmartsystems.zigbee library/framework it depends on which just made me a little curious if you happen to know if this ZigBeeTimeExtension and ZigbeeUtcTime class / Zigbee Time Cluster + time client/server (ZCL time server) support is used and required by any Zigbee (3.0) devices in the available real-world consumer products and not just commercial products for Zigbee Smart Energy (Zigbee SE) devices like those used by energy utility companies (such as in the electricity meter they install in your house)? See:

openhab/org.openhab.binding.zigbee#791

and

zsmartsystems/com.zsmartsystems.zigbee#1371

Silicon Labs have an sample Zigbee application example of a such device with "Zigbee RTC Time Synchronization":

https://github.com/SiliconLabs/zigbee_applications/tree/master/zigbee_rtc_time_sync

"In a common Zigbee network, the gateway normally has the capability of connecting to the internet, so it can get the date and time through NTP. Therefore, the gateway can act as the time server to provide the time source for the other Zigbee devices. This example demonstrates how we synchronize the date and time in the Zigbee network. On the device side, the local date and time will be kept by the plugin Simple Clock."

I do not have any such device however searching a little online a found some references that Zigbee Time Cluster is probably used in some Zigbee thermostats(?) as well as the more obviously smart energy (electricity and water consumption management devices that act as DLMS/COSEM bridges) such as for example smart reader products for the "HAN" (Home Area Network) ports that are common in electricity meters in Scandinavia and P1 port in Holland.

https://www.digi.com/resources/documentation/digidocs/90001931/general_operation/general_operation.html

https://community.silabs.com/s/question/0D51M00007xeTqISAU/zigbee-time-cluster?language=en_US

https://e2e.ti.com/support/wireless-connectivity/zigbee-thread-group/zigbee-and-thread/f/zigbee-thread-forum/759125/cc2530-zstack-3-linux-gateway---add-support-for-coordinator-time-cluster

https://digidotcom.github.io/xbee_ansic_library/group__zcl__time.html

https://community.nxp.com/t5/Wireless-Connectivity/JN5179-ZigBee-3-0-Time-Cluster/m-p/613616

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/zboss/3.11.1.177/group___z_b___z_c_l___t_i_m_e___a_t_t_r_s.html

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/zboss/3.12.1.0/group___z_b___z_c_l___t_i_m_e___c_o_m_m_a_n_d_s.html

This creates a ZigBeeUtcTime class for managing time on a remote device. It then supports a ZigBeeTimeExtension which in turn can provide a local ZclTimeClient or ZclTimeServer to manage the time on the remote device. The ZclTimeServer is relatively simple in that it just responds to requests from the device. The ZclTimeClient is in itself also simple in that it provides methods to set the time on the remote. The ZigBeeTimeExtension tries to automate the time management by working out drift rates, and setting the clock proactively if the time has drifted outside spec and the device didn't update the time through a request to the ZclTimeServer. There is also a ZigBeeConsoleTimeCommand console command to get or set the time, and display the various information. This is potentially a breaking change if people are using time at the moment since this changes some interfaces from Calendar to ZigBeeUtcTime.