Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quirk for IKEA SYMFONISK sound remote gen 2 (E2123) #2236

Closed
wants to merge 8 commits into from
Closed

Add quirk for IKEA SYMFONISK sound remote gen 2 (E2123) #2236

wants to merge 8 commits into from

Conversation

MichelBrodatzki
Copy link

@MichelBrodatzki MichelBrodatzki commented Feb 28, 2023

Initial support for the new SYMFONISK sound remote gen 2. This might need some testing with more software versions as noted in issue #2223.

Every button can be used as a trigger for automations (and supported buttons even with long press and double press).

zhaquirks/ikea/__init__.py Outdated Show resolved Hide resolved
zhaquirks/ikea/symfonisk.py Outdated Show resolved Hide resolved
zhaquirks/ikea/__init__.py Outdated Show resolved Hide resolved
@TheJulianJES
Copy link
Collaborator

Without relaying the events from the custom V1ShortcutCluster to the LevelControl cluster, no zha_events are generated, right?

@MichelBrodatzki
Copy link
Author

Yes, that's correct. The log shows that the server_command was parsed correctly, but no zha_event is generated.

@MattWestb
Copy link
Contributor

If i not have reading wrong is the output cluster LevelControl.cluster_id, and V1ShortcutCluster.cluster_id, on endpoint 1 the same type (0x0008) and its can only being one time on one endpoint.
And i wondering way not using the scene cluster if like using one ZCL one or doing one complete one one ?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 4336585690

  • 17 of 22 (77.27%) changed or added relevant lines in 2 files are covered.
  • 104 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.02%) to 83.767%

Changes Missing Coverage Covered Lines Changed/Added Lines %
zhaquirks/ikea/init.py 12 17 70.59%
Files with Coverage Reduction New Missed Lines %
zhaquirks/tuya/init.py 104 75.12%
Totals Coverage Status
Change from base Build 4287942731: -0.02%
Covered Lines: 6858
Relevant Lines: 8187

💛 - Coveralls

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 77.27% and project coverage change: +0.04 🎉

Comparison is base (f6ab87e) 83.72% compared to head (5a60f67) 83.76%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2236      +/-   ##
==========================================
+ Coverage   83.72%   83.76%   +0.04%     
==========================================
  Files         257      257              
  Lines        8190     8187       -3     
==========================================
+ Hits         6857     6858       +1     
+ Misses       1333     1329       -4     
Impacted Files Coverage Δ
zhaquirks/ikea/__init__.py 70.58% <70.58%> (-0.57%) ⬇️
zhaquirks/ikea/symfonisk.py 100.00% <100.00%> (ø)
zhaquirks/xiaomi/aqara/sensor_switch_aq3.py 76.31% <0.00%> (-0.61%) ⬇️
zhaquirks/tuya/__init__.py 75.62% <0.00%> (ø)
zhaquirks/ikea/shortcutbtn.py 100.00% <0.00%> (ø)
zhaquirks/ikea/tradfriplug.py 100.00% <0.00%> (ø)
zhaquirks/xiaomi/aqara/sensor_swit.py
zhaquirks/gledopto/glc009p.py 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@MichelBrodatzki
Copy link
Author

HA! Fixed it! 🎉

@MichelBrodatzki
Copy link
Author

@MattWestb
I think the important thing is that the cluster_id is different, which it is (LevelControl with 0x0008 and V1Shortcut with 0xFC7F) :)

@MattWestb
Copy link
Contributor

Im very sorry but i dont understand way using the ZCL level cluster for the shortcut commands.
In some week we is getting one more device that (more then likely) is using same commands then the gen 2 of shortcut button is being released.
My intersession is implanting one IKEA shortcut cluster in the INIT and if needed with more version / classes and then using it in different devices that is needing it in there quirks.
And then its not one ZCL commands is for my most logical using EventableCluster and not some ZCL classes that is only making things more strange (ala tuya).

Also new 2 gen devices shall having own quirks and not being mixes with gen i devices quirk for not making it one large mess of it.

@MattWestb
Copy link
Contributor

Sniff from V1 device command short press:

ZigBee Network Layer Data, Dst: 0x0000, Src: 0x0664
ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 1
    Frame Control Field: Data (0x00)
    Destination Endpoint: 1
    Cluster: Manufacturer Specific (0xfc7f)
    Profile: Home Automation (0x0104)
    Source Endpoint: 1
    Counter: 84
ZigBee Cluster Library Frame, Mfr: Ikea of Sweden (0x117c)
    Frame Control Field: Cluster-specific (0x15)
    Manufacturer Code: Ikea of Sweden (0x117c)
    Sequence Number: 88
    Command: Unknown (0x01)
Data (2 bytes)
    Data: 0101
    [Length: 2]

@MichelBrodatzki
Copy link
Author

I tried changing the cluster to a EventableCluster but the zha_events still did not fire. I'm using the level cluster, because it has unused commands in this device, so I just proxy the shortcut button presses to the level cluster.

We'd need to look at where or why exactly the zha_event does not fire from new clusters.

@MattWestb
Copy link
Contributor

Working implementation is here but its using little different commands like rotating and so on. class TuyaSmartRemoteOnOffCluster(OnOff, EventableCluster):
But we shall not using OnOff as base then it can making problems with the for V1 devices that is having one on the same endpoint.

@MichelBrodatzki
Copy link
Author

MichelBrodatzki commented Mar 5, 2023

I've looked at that code and IMO my implementation does the same.

The only difference is that Tuya sends their custom commands on the OnOff cluster, so replacing the OnOff cluster with a custom OnOff cluster that only adds the custom commands works. But as you can see in lines 1003 and 1008 they also need to change the command_id of the custom commands to command_ids from the default OnOff cluster.

IKEA chose to send their custom commands on a non-standard cluster, so in addition to changing the command_ids I also need to send them to a standard cluster.

I think that the zha_events might be fired, but dropped, as ZHA / Home Assistant might not have any handlers for non-standard events. The reason I think that is because if you trigger a standard event the ZHA logs don't log the event string, but a name for that event (e.g. triggering "move_with_on_off" will result in a log entry with "[...] Move With On Off event was fired with parameters: [...]"). If I find the time I might look into the implemention of ZHA to see where the mapping of event string <-> event name happens. Maybe there's a way to convice ZHA to accept our non-standard events.

@MichelBrodatzki
Copy link
Author

MichelBrodatzki commented Mar 5, 2023

So after looking at the ZHA component for a few minutes what I think is happening is the following:

I think the way forward would be to see which cluster_id IKEA will use going forward and opening a pull request at home-assistant/core for adding it to the manufacturer specific channels module

Fun fact: my approach with the log file was not correct. It turns out, the logger just replaces underscores with spaces and title cases the string. But my guess that it might be because it's a non-standard (manufacturer specific) cluster IKEA uses turned out to be right.

@TheJulianJES
Copy link
Collaborator

TheJulianJES commented Mar 5, 2023

Yeah, LevelControl parsing is here (cluster_command): https://github.com/home-assistant/core/blob/84402a9ae0fd3dce38ee0752b73bc612be985920/homeassistant/components/zha/core/channels/general.py#L271-L288
Device action schemas are here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/device_action.py

This PR did it for Inovelli Blue devices: https://github.com/home-assistant/core/pull/79106/files

Not sure if we really need it for this IKEA device though(?)

@MattWestb
Copy link
Contributor

MattWestb commented Mar 5, 2023

The right cluster shall being Matter 0x003b Switch but i think (Z)HA have not implanting it.
From Matter 1.0:

1.11.7. Events
This cluster SHALL support these events:
Id Name Access Conformance
0 SwitchLatched V LS
1 InitialPress V MS
2 LongPress V MSL
3 ShortRelease V MSR
4 LongRelease V MSL
5 MultiPressOngoing V MSM
6 MultiPressComplete V MSM

Its 100% the commands V2 is sending from EP 1 and 2.
And IKEA have putting it as manufacture cluster then its not in the ZCL R8.

@MichelBrodatzki
Copy link
Author

MichelBrodatzki commented Mar 5, 2023

Not sure if we really need it for this IKEA device though(?)

I think we should wait and see which cluster_id IKEA keeps using and then add that to ZHA directly. It's a nice thing to support older firmwares, but that's where quirks shine the most in my opinion. Adding multiple variants of IKEA devices to ZHA even though they get updated to all use the same cluster_id would be a lot of clutter for nearly no benefit (assuming the devices you buy at IKEA will eventually ship with the newer firmware).

@MichelBrodatzki
Copy link
Author

Its 100% the commands V2 is sending from EP 1 and 2.

That's an interesting fact that the newer version sticks to the Matter standard. I hope that going forward this will be their standard. V1 does not seem to conform to this standard, that's why "button released" isn't implemented in my code.

@MattWestb
Copy link
Contributor

MattWestb commented Mar 5, 2023

New IKEA devices is using the same function / clusters so do the PM25 cluster implanted in Starkvind shall being moved to INIT and then Vidstyrka can using it then we getting the device.
And the 0x003b Switch im very sure is being reused for the upcoming Shortcut switch 2.
I hope IKEA is fixing the not OK implanted in V2 function 5 MultiPressOngoing (i think it shall being sent for press then doing multiple pressing until the last done that shall being command 6.

IKEA is the coordinator for Europe of the Matter group so they is having the knowledge and also using it in there products.

My feeling V1 its little out of date and can being implanted with level cluster but for V2 and newer is my feeling its better doing it so its working general for future device / firmware versions.
It was the same with the scene cluster special for the 5 and 4 button remotes one function and using it all over for the life cycle of the devices.

The missing part on this device is its not using the Matter media control cluster for the media functions but that can coming in some years.

One question is HA implanting Matter 1.0 then we can using that and only changing the cluster type from 0xFC80 to 0x003b in the quirk and HA is doing the rest for V2.
IKEA cant using 0x003b then its out of spec in ZCL R8 but i can being changed in the future then Zigbee R23 is being released (shall being the same for Zigbee and Matter).

@MattWestb
Copy link
Contributor

HA Matter shall having support for switch devices !!
https://www.home-assistant.io/integrations/matter/#current-state-of-the-integration

Platform support in Home Assistant is currently limited to switches, lights, and (binary) sensors. The light platform is limited to on/off and brightness control only, support for color and color temperature control will be added soon.

So only changing the cluster number and sending the commands to HA ;-)) (if its working).

@MattWestb
Copy link
Contributor

@MichelBrodatzki @javicalle was helping and im is using this in IKEA INIT:

class ShortcutV2Cluster(EventableCluster):
    """Ikea Shortcut Button Cluster Variant 2."""

    name = "ShortcutClusterV2"
    cluster_id = 0xFC80

    server_commands = {
        0x00: foundation.ZCLCommandDef(
            "SwitchLatched",
            {
                "Data": t.int8s,
            },
            False,
            is_manufacturer_specific=True,
       ),
        0x01: foundation.ZCLCommandDef(
            "InitialPress",
            {
                "Data": t.int8s,
            },
            False,
            is_manufacturer_specific=True,
       ),
       0x02: foundation.ZCLCommandDef(
            "LongPress",
            {
                "Data": t.int8s,
               },
            False,
            is_manufacturer_specific=True,
        ),
        0x03: foundation.ZCLCommandDef(
            "ShortRelease",
            {
                "Data": t.int8s,
            },
            False,
            is_manufacturer_specific=True,
        ),
        0x04: foundation.ZCLCommandDef(
            "LongRelease",
            {
                "Data": t.int8s,
            },
            False,
            is_manufacturer_specific=True,
        ),
        0x05: foundation.ZCLCommandDef(
        "MultiPressOngoing",
            {
                "Data": t.int8s,
            },
            False,
            is_manufacturer_specific=True,
        ),
        0x06: foundation.ZCLCommandDef(
            "MultiPressComplete",
            {
                "Data": t.int16s,
            },
            False,
            is_manufacturer_specific=True,
        ),
    }

And is getting all very nice as zha_event and can doing DA from it.

event_type: zha_event
data:
  device_ieee: 1c:34:f1:ff:fe:78:57:15
  unique_id: 1c:34:f1:ff:fe:78:57:15:3:0xfc80
  device_id: 7b803a8f3912b70e1949639ccf9e0ad5
  endpoint_id: 3
  cluster_id: 64640
  command: ShortRelease
  args:
    - 0
  params:
    Data: 0
origin: LOCAL
time_fired: "2023-03-06T07:07:59.383418+00:00"
context:
  id: 01GTTVZ7GQ4F8MAC62ZT1VMWG2
  parent_id: null
  user_id: null

Perhaps you can using the same approach but spiting the the data in more parms like is being dont for the IKEA Scenes cluster in the INIT:

    server_commands.update(
        {
            0x0007: foundation.ZCLCommandDef(
                "press",
                {"param1": t.int16s, "param2": t.int8s, "param3": t.int8s},
                False,
                is_manufacturer_specific=True,
            ),

I dont knowing if its working with V1 data structure but i think its one more clean way doing it and can being worth one try.

@MattWestb
Copy link
Contributor

MattWestb commented Mar 14, 2023

I have made one PR for both versions and have getting the V1 working by adding the shortcut cluster as on both in and out on the EP1 and getting the events working and have making the common DAs in one class and then adding the device specific ones in the device class.
I have used most of your code and adopting it so its fitting together with V2 device class.
#2273

Great thanks for your help !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants