Skip to content

Instantly share code, notes, and snippets.

@HarvsG
Last active October 30, 2024 22:54
Show Gist options
  • Save HarvsG/d43344cbe07e046cdda50c2458018c33 to your computer and use it in GitHub Desktop.
Save HarvsG/d43344cbe07e046cdda50c2458018c33 to your computer and use it in GitHub Desktop.
Adding IKEA Tradfri Devices with ZHA on Home Assistant

Shortcut and On/Off switches

  1. Remove back cover with philips scredriver and instert provided battery
  2. In home assistant select a ZHA always-on zigbee device - such as a powered light or signal repeater in the same room the shortcut button will end up in
  3. Select "Add device via this device"
  4. Press the pair button 4 times on the back of the shortcut button
  5. Wait
  6. If using an On/Off switch and you want to bind it to a bulb for non-controller dependant control (i.e will work if home assistant is down)

Pairing On/Off Switches to IKEA Bulbs

For firmware versions 2.3.0.75 or greater.

Before version 2.3.075 The IKEA on/off switches only bind to zigbee groups After they only bind to individual devices: The most reliable method seems to be: In ZHA for me that process is bring up the device page for the switch, 3 dots the the right of the reconfigure button, manage ZigBee device, bindings.

  1. Consider updating to the latest firmware, as updates alter this functionality.
  2. Unbind the switch from all devices including the co-ordinator
  3. Unbind from all groups (check all clusters) <-- not sure if necessary
  4. Reconfigure the device from the ZHA UI <-- not sure if necessary.
  5. Unbind from the coordinator again <-- not sure if necessary
  6. Bind with the desired lights
  7. Re-bind with the coordinator (This ensures the homeassistant UI acutally shows the state changes)
  8. If the lights do not update their status in the UI when turned on or off by the switch, then click RECONFIGURE DEVICE for each light, making sure to refresh the page between each device

Note about shortcut buttons

At software version number 2.3.015 they have 3 possible comands "on" (triggered with a short press) "move_with_on_off" triggered by a long press and "stop" triggered by a release of a long press. Each message may also be duplicated many times (apparently this is within the zigbee spec, but you may have to control for it in node-red (this node is helpful)

Somewhere between 2.3.015 and 2.3.80 the gain the "off" function which is tiggered by a double click. The message duplication is also improved ?completeley resolved?

Checking software version numbers in ZHA

  1. Device page of the device in question
  2. Manage Clusters
  3. "Basic (Endpoint id: 1, Id: 0x0000, Type: in)"
  4. Cluster Attributes -> "sw_build_id (id: 0x4000)"
  5. Click "Get Zigbee Attribute"
  6. If device is battery powered, trigger it somehow
  7. The version should appear in the "Value" box

Updating software in ZHA

I think updating software is generally a good idea, but IKEA often changes functionality with little warning and so it may break some of you systems. ZHA way of managing updates (if enables) is to silently update your devices in the background. Which may mean that things can silently break.

Updating On/Off remotes and shortcut buttons

This post on reddit by u/Wwalltt is currently a good overview of how updates work in ZHA

Version info is as follows from the IKEA server (no changelog): http://fw.ota.homesmart.ikea.net/feed/version_info.json

Tradfri changelog https://ww8.ikea.com/ikeahomesmart/releasenotes/releasenotes.html

Or official docs are a little better than they were: https://www.home-assistant.io/integrations/zha/#ota-firmware-updates

  • As of 2.3.075 or later on switches they go from being able to bind groups and not devices to the opposite
  • For the shortcut buttons as of 2.3.0.75, they gain the off command on double press and the duplicaiton problem is fixed.

In ZHA:

  1. Ensure you have OTA updates enabled in ZHA (see above)
  2. In my experience devices begin updating soon after joining the network anyway - you can skip to step 8/9 to check
  3. Select the device you want to update
  4. Select Manage Clusters
  5. Select Ota (Endpoint id: 1, Id: 0x0019, Type: out)
  6. In the Cluster Commands drop-down, (not Cluster Attributes) select image_notify (id: 0x0000)
  7. Click ISSUE ZIGBEE COMMAND whilst waking the device
  8. Wait One device took approx 2 hours(!)
    • there is no obvious way to tell if the update has started except to SSH into the HA and run tail -f home-assistant.log | egrep zigpy which should show an increasing upgrade percentage if you have DEBUG level logging for zigpy/ZHA.
  9. You can track the progress with tail -f home-assistant.log | egrep "OTA upgrade progress:"
@barcik75
Copy link

Hi all, any hints on what to put in manufacturer_code, image_type and new_file_version boxes? Without the values, I can't call any commands.

I also noticed that I'm unable to read any attribute: Every time I try to read any attribute I get an error sign and nothing happens.

I have this in logs:

2023-03-17 09:49:00.161 DEBUG (MainThread) [homeassistant.components.zha.api] Get bindable devices: source_ieee: [54:0f:57:ff:fe:f5:88:13], bindable devices: [[{'ieee': '00:12:4b:00:24:c2:d1:5a', 'nwk': 0x0000, 'manufacturer': 'Texas Instruments', 'model': 'CC1352/CC2652, Z-Stack 3.30+ (build 20221226)', 'name': 'Texas Instruments CC1352/CC2652, Z-Stack 3.30+ (build 20221226)', 'quirk_applied': False, 'quirk_class': 'zigpy_znp.zigbee.device.ZNPCoordinator', 'manufacturer_code': 0, 'power_source': 'Mains', 'lqi': None, 'rssi': None, 'last_seen': '2023-03-17T09:21:35', 'available': True, 'device_type': 'Coordinator', 'signature': {'node_descriptor': 'NodeDescriptor(logical_type=<LogicalType.Coordinator: 0>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice|AlternatePanCoordinator: 143>, manufacturer_code=0, maximum_buffer_size=80, maximum_incoming_transfer_size=160, server_mask=11265, maximum_outgoing_transfer_size=160, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=True, *is_coordinator=True, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=False, *is_security_capable=False)', 'endpoints': {1: {'profile_id': 260, 'device_type': '0x0400', 'in_clusters': ['0x0000', '0x0006', '0x000a', '0x0019', '0x0501'], 'out_clusters': ['0x0001', '0x0020', '0x0500', '0x0502']}, 2: {'profile_id': 49246, 'device_type': '0x0820', 'in_clusters': ['0x0000'], 'out_clusters': []}}}, 'active_coordinator': True, 'entities': [], 'neighbors': [{'device_type': 'EndDevice', 'rx_on_when_idle': 'Off', 'relationship': 'Child', 'extended_pan_id': '82:f8:75:26:cf:1f:54:a3', 'ieee': '00:12:4b:00:25:0e:01:af', 'nwk': '0x17AE', 'permit_joining': 'Unknown', 'depth': '1', 'lqi': '178'}], 'routes': [], 'endpoint_names': [{'name': 'CONTROLLER'}, {'name': 'IAS_CONTROL'}], 'user_given_name': None, 'device_reg_id': '575c7b99cc16aeeffea75e71cc0bda30', 'area_id': 'biuro'}]]
2023-03-17 09:49:00.188 DEBUG (MainThread) [homeassistant.components.zha.api] Requested attributes for: cluster_id: 9, cluster_type: 'in', endpoint_id: 1, response: [{'id': 0, 'name': 'alarm_count'}, {'id': 65533, 'name': 'cluster_revision'}, {'id': 65534, 'name': 'attr_reporting_status'}]
2023-03-17 09:49:01.949 DEBUG (MainThread) [homeassistant.components.zha.api] Requested attributes for: cluster_id: 0, cluster_type: 'in', endpoint_id: 1, response: [{'id': 0, 'name': 'zcl_version'}, {'id': 1, 'name': 'app_version'}, {'id': 2, 'name': 'stack_version'}, {'id': 3, 'name': 'hw_version'}, {'id': 4, 'name': 'manufacturer'}, {'id': 5, 'name': 'model'}, {'id': 6, 'name': 'date_code'}, {'id': 7, 'name': 'power_source'}, {'id': 8, 'name': 'generic_device_class'}, {'id': 9, 'name': 'generic_device_type'}, {'id': 10, 'name': 'product_code'}, {'id': 11, 'name': 'product_url'}, {'id': 12, 'name': 'manufacturer_version_details'}, {'id': 13, 'name': 'serial_number'}, {'id': 14, 'name': 'product_label'}, {'id': 16, 'name': 'location_desc'}, {'id': 17, 'name': 'physical_env'}, {'id': 18, 'name': 'device_enabled'}, {'id': 19, 'name': 'alarm_mask'}, {'id': 20, 'name': 'disable_local_config'}, {'id': 16384, 'name': 'sw_build_id'}, {'id': 65533, 'name': 'cluster_revision'}, {'id': 65534, 'name': 'attr_reporting_status'}]
2023-03-17 09:49:08.950 DEBUG (MainThread) [zigpy.zcl] [0x8EA6:1:0x0000] Sending request header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.GLOBAL_COMMAND: 0>, is_manufacturer_specific=False, direction=<Direction.Server_to_Client: 0>, disable_default_response=0, reserved=0, *is_cluster=False, *is_general=True, *is_reply=False), tsn=28, command_id=<GeneralCommand.Read_Attributes: 0>, *direction=<Direction.Server_to_Client: 0>, *is_reply=False)
2023-03-17 09:49:08.951 DEBUG (MainThread) [zigpy.zcl] [0x8EA6:1:0x0000] Sending request: Read_Attributes(attribute_ids=[16384])
2023-03-17 09:49:08.952 DEBUG (MainThread) [zigpy.device] [0x8ea6] Extending timeout for 0x1c request
2023-03-17 09:49:13.864 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x9318](TRADFRI SHORTCUT Button): Device seen - marking the device available and resetting counter
2023-03-17 09:49:13.864 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x9318](TRADFRI SHORTCUT Button): Update device availability - device available: True - new availability: True - changed: False

Misiu, I had a similar problem. And I don't have Ikea bulbs either. I moved the switch closer to the gate and pressed the Read Attributes button until the value showed up, which was about 10 times.

@silversparker
Copy link

I managed to update the switch version to 2.3.080 (according to the Ikea website, the latest version for this switch) But I still don't have Action entities, only Diagnostic entities. I'm using ZHA, a colleague is using ZigBee2MQTT and there I have Action related entities, not just Diagnostics. It's funny that pressing the button longer, twice or once briefly generates entries in the Event Log, but I can't control them in any way (creating automation) Anyone have any ideas on how to force the controls to appear? Switch to ZigBee2MQTT? Anything else?

I have a similar problem with the STYRBAR button. Entities in the Diagnostics category are available.

But if there are events showing then youre ready to go? Just use the trigger "device" in your automations and set the trigger of that device to short press or long press. Or am I misunderstanding you?

@barcik75
Copy link

I managed to update the switch version to 2.3.080 (according to the Ikea website, the latest version for this switch) But I still don't have Action entities, only Diagnostic entities. I'm using ZHA, a colleague is using ZigBee2MQTT and there I have Action related entities, not just Diagnostics. It's funny that pressing the button longer, twice or once briefly generates entries in the Event Log, but I can't control them in any way (creating automation) Anyone have any ideas on how to force the controls to appear? Switch to ZigBee2MQTT? Anything else?
I have a similar problem with the STYRBAR button. Entities in the Diagnostics category are available.

But if there are events showing then youre ready to go? Just use the trigger "device" in your automations and set the trigger of that device to short press or long press. Or am I misunderstanding you?

You understood me right :) So far in all automations I have used entities and "forgot" that devices can also be used. Thanks for the hint, now everything is ok.

@dect0r
Copy link

dect0r commented May 10, 2023

Hi all, any hints on what to put in manufacturer_code, image_type and new_file_version boxes? image Without the values, I can't call any commands.

I also noticed that I'm unable to read any attribute: image Every time I try to read any attribute I get an error sign and nothing happens.

I have this in logs:

2023-03-17 09:49:00.161 DEBUG (MainThread) [homeassistant.components.zha.api] Get bindable devices: source_ieee: [54:0f:57:ff:fe:f5:88:13], bindable devices: [[{'ieee': '00:12:4b:00:24:c2:d1:5a', 'nwk': 0x0000, 'manufacturer': 'Texas Instruments', 'model': 'CC1352/CC2652, Z-Stack 3.30+ (build 20221226)', 'name': 'Texas Instruments CC1352/CC2652, Z-Stack 3.30+ (build 20221226)', 'quirk_applied': False, 'quirk_class': 'zigpy_znp.zigbee.device.ZNPCoordinator', 'manufacturer_code': 0, 'power_source': 'Mains', 'lqi': None, 'rssi': None, 'last_seen': '2023-03-17T09:21:35', 'available': True, 'device_type': 'Coordinator', 'signature': {'node_descriptor': 'NodeDescriptor(logical_type=<LogicalType.Coordinator: 0>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice|AlternatePanCoordinator: 143>, manufacturer_code=0, maximum_buffer_size=80, maximum_incoming_transfer_size=160, server_mask=11265, maximum_outgoing_transfer_size=160, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=True, *is_coordinator=True, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=False, *is_security_capable=False)', 'endpoints': {1: {'profile_id': 260, 'device_type': '0x0400', 'in_clusters': ['0x0000', '0x0006', '0x000a', '0x0019', '0x0501'], 'out_clusters': ['0x0001', '0x0020', '0x0500', '0x0502']}, 2: {'profile_id': 49246, 'device_type': '0x0820', 'in_clusters': ['0x0000'], 'out_clusters': []}}}, 'active_coordinator': True, 'entities': [], 'neighbors': [{'device_type': 'EndDevice', 'rx_on_when_idle': 'Off', 'relationship': 'Child', 'extended_pan_id': '82:f8:75:26:cf:1f:54:a3', 'ieee': '00:12:4b:00:25:0e:01:af', 'nwk': '0x17AE', 'permit_joining': 'Unknown', 'depth': '1', 'lqi': '178'}], 'routes': [], 'endpoint_names': [{'name': 'CONTROLLER'}, {'name': 'IAS_CONTROL'}], 'user_given_name': None, 'device_reg_id': '575c7b99cc16aeeffea75e71cc0bda30', 'area_id': 'biuro'}]]
2023-03-17 09:49:00.188 DEBUG (MainThread) [homeassistant.components.zha.api] Requested attributes for: cluster_id: 9, cluster_type: 'in', endpoint_id: 1, response: [{'id': 0, 'name': 'alarm_count'}, {'id': 65533, 'name': 'cluster_revision'}, {'id': 65534, 'name': 'attr_reporting_status'}]
2023-03-17 09:49:01.949 DEBUG (MainThread) [homeassistant.components.zha.api] Requested attributes for: cluster_id: 0, cluster_type: 'in', endpoint_id: 1, response: [{'id': 0, 'name': 'zcl_version'}, {'id': 1, 'name': 'app_version'}, {'id': 2, 'name': 'stack_version'}, {'id': 3, 'name': 'hw_version'}, {'id': 4, 'name': 'manufacturer'}, {'id': 5, 'name': 'model'}, {'id': 6, 'name': 'date_code'}, {'id': 7, 'name': 'power_source'}, {'id': 8, 'name': 'generic_device_class'}, {'id': 9, 'name': 'generic_device_type'}, {'id': 10, 'name': 'product_code'}, {'id': 11, 'name': 'product_url'}, {'id': 12, 'name': 'manufacturer_version_details'}, {'id': 13, 'name': 'serial_number'}, {'id': 14, 'name': 'product_label'}, {'id': 16, 'name': 'location_desc'}, {'id': 17, 'name': 'physical_env'}, {'id': 18, 'name': 'device_enabled'}, {'id': 19, 'name': 'alarm_mask'}, {'id': 20, 'name': 'disable_local_config'}, {'id': 16384, 'name': 'sw_build_id'}, {'id': 65533, 'name': 'cluster_revision'}, {'id': 65534, 'name': 'attr_reporting_status'}]
2023-03-17 09:49:08.950 DEBUG (MainThread) [zigpy.zcl] [0x8EA6:1:0x0000] Sending request header: ZCLHeader(frame_control=FrameControl(frame_type=<FrameType.GLOBAL_COMMAND: 0>, is_manufacturer_specific=False, direction=<Direction.Server_to_Client: 0>, disable_default_response=0, reserved=0, *is_cluster=False, *is_general=True, *is_reply=False), tsn=28, command_id=<GeneralCommand.Read_Attributes: 0>, *direction=<Direction.Server_to_Client: 0>, *is_reply=False)
2023-03-17 09:49:08.951 DEBUG (MainThread) [zigpy.zcl] [0x8EA6:1:0x0000] Sending request: Read_Attributes(attribute_ids=[16384])
2023-03-17 09:49:08.952 DEBUG (MainThread) [zigpy.device] [0x8ea6] Extending timeout for 0x1c request
2023-03-17 09:49:13.864 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x9318](TRADFRI SHORTCUT Button): Device seen - marking the device available and resetting counter
2023-03-17 09:49:13.864 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x9318](TRADFRI SHORTCUT Button): Update device availability - device available: True - new availability: True - changed: False

You only have to select QueryJitter and leave the slider unchanged. This triggered the OTA for me

@Alveoli
Copy link

Alveoli commented Sep 29, 2023

Very informative posts, thank you.

I just bought a Tradfri Shortcut button Type E1812 two days and had similar issue - it binds to ZHA, I can see the battery level but no events. I wasn't able to connect to get the sw_build_id (same red exclamation mark error above).

Frustrated, I left it for two days... and this morning it's just started eventing! I did nothing. Didn't check or update the firmware.

Hopefully it continues to work.

@dotkrnl
Copy link

dotkrnl commented Sep 2, 2024

I got three trays of clearance TRADFRI Shortcut Buttons yesterday and was frustrated as they only reported battery status but no events at all, lol. I found a few comments stating that the SkyConnect doesn't work with it, so I was worried I had just bought three trays of bricks. Fortunately, after trying for 5+ hours, I figured out a reasonable flow to make them work with ZHA.

  1. To get a clean start, reboot your HA box. Somehow I got into an unstable state where, despite a lot of effort, I couldn't proceed with the following steps.
  2. Add the TRADFRI Shortcut Button using a Zigbee router by opening a wired Zigbee device, such as a light bulb, in HA, selecting Add devices via this device. I'm not sure if this is needed for coordinators other than SkyConnect, but I was unable to get it to work without a router.
  3. Press the "Pair" button on the back of the TRADFRI Shortcut Button six times quickly; no need to keep pressing. Wait until the device is interviewed and configured. If it gets stuck for a long time, reboot the HA box, remove the added device, and repeat from Step 2. Proceed to step 4 when you get the configured device added to HA.
  4. Try pushing the button and see if you get a ZHA event. If not, repeat this step until you do: While pressing the button every second to keep it awake, click Reconfigure for the shortcut button on HA and start reconfiguring. Show all details and wait until it shows configuration done and all ticks are green. If not, repeat this step. If it gets stuck, press the "Pair" button six times quickly and reconfigure again. Try to see if you have a ZHA event now; if not, repeat.
  5. Now you have a stable connection with the button! If you're satisfied with this, you're done. If you'd like to upgrade, follow the next steps.
  6. As of today, OTA for IKEA devices in Zigpy has been disabled by default. Enable it following https://github.com/zigpy/zigpy/wiki/OTA-Configuration. You may need to wait for the firmware update to appear in HA.
  7. Open the Firmware update dialog on HA in the device. While pressing the button intermittently to keep it awake, start the upgrade. Keep pressing the button until the upgrade actually starts and the percentage value is shown.
  8. Wait about two hours for the upgrade to complete. For me, it works automatically, but some comments mentioned that clicking the button every few minutes to keep it awake helps.
  9. Once the upgrade is done, remove the battery from the button and reinstall it. You should now be all set. FYI, I use HA Automation to listen to the On ZHA event of the button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment