-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[hue] Add support for enabling automations (API v2) #16980
Conversation
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur this is my first contribution; it has not been tested; but you may want to take a look at it (in case you think I am on a wrong track).. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur I tested it and it fails. Reasons are as follows:
FACIT: this will take much more time and effort than I originally expected! |
Thanks for giving it a go.
Indeed. I just had a quick look in Postman, and it seems like sensors etc. have something like this: "state": {
"model_id": "SML001",
"source_type": "device"
}, At least on my system, those without this
I'm not sure we need all that since we are only interested in disabling/enabling automations. So we can read this state on first level without defining any nested DTO structures:
And likewise we can set this state like described in #16904. So maybe it wouldn't be that hard? |
Of course we might look into if anything else makes sense to be able to control. We can already enable/disable motion sensors (as an example) directly through its Thing. So I guess the API makes it possible to configure everything like behavior of buttons, lux levels for motion sensors, time intervals when light should be dimmed etc. Currently I don't see a use-case for such fine-grained control - not saying there isn't one though. 😉 If we'd come back to this at some point, Thing Actions would probably be a more appropriate way for controlling this. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur as a result of my latest commits, it is now working fully; the only problem is that the Bridge contains (in my case) 22 |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur I just added an EDIT: however the channels do still contain my Tap Dial switch (see below) which is apparently also without a |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur for info: My Tap Dial switch is a device that I purchased for testing purposes. It was actually stored in a box in my shed, out of range of the Hue Bridge, and not programmed to any real room or zone. I think that was the reason why the respective behavior_instance did not have a 'state' element. I have now connected it properly to my live system, and now it does have a 'state' element. So now it is properly excluded from the automations list - see below. Notwithstanding this, I think that perhaps the absence of a 'state' element is perhaps not the proper "official" way to filter automations. Reason is that in the Hue App the Tap Dial switch did never appear -- irrespective of whether it was properly configured or not. I wonder if we should in any case look for another way for filtering automations. => WDYT? |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good! I have given it a test ride, and it works really well.
I'm wondering if it would be possible to update automation channels automatically without having to disable and enable the Thing (i.e. after adding/removing/renaming automations in the app)?
Polling might not be desirable, but perhaps it's possible to trigger a refetch when receiving a message about an unknown automation being updated? That would of course only solve the problem of adding channels, not removing them. And also I don't know if the binding is even receiving such messages.
bundles/org.openhab.binding.hue/src/main/resources/OH-INF/thing/channels.xml
Show resolved
Hide resolved
Yes I could do that. |
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@jlaur I have committed a change that should automatically refresh the automation channels if an event comes in containing an automation resource that is not yet known. I am rather busy, so I have not had the chance to test it, but I made the commit in case you can test it, and want to merge it before 4.2 release. |
Thanks. I just gave it a spin as well, and I now also see three of my motion sensors added as automations. I don't know why three, because I have more than that, but I'll have a closer look within the next days. EDIT: A quick look into the returned JSON shows that only three of my motion sensors are part of the behavior instance response. They have no device element within the "state": {
"model_id": "SML003",
"source_type": "device"
}, EDIT: For me it seemed to do the trick to combine with your previous proposal: public boolean isAutomationResource() {
Configuration configuration = this.configuration;
return (Objects.isNull(state) || state.isJsonNull()) && Objects.nonNull(configuration)
&& !configuration.hasDeviceElement() && (ResourceType.BEHAVIOR_INSTANCE == getType());
} |
@andrewfg - and now I experienced another quirk. I enabled one automation during my tests, and disabled it again right after. But it seemed to be running, and I now see this in the response: "enabled": false,
"state": {
"gts_state": "stopped"
}, and: "status": "running", so with the code proposed above, this automation is now left out. I will need to get back to this. |
It seems to be difficult to find a filter which avoids both false negatives and false positives. I assume that the Hue App is using some kind of filter too.. EDIT: in my case it seems that the presence of a EDIT2: .. or perhaps there is some "magic" in cross referencing the EDIT3: to answer my own question, the answer is "yes"!! The
|
Signed-off-by: AndrewFG <software@whitebear.ch>
@jlaur phew .. hopefully my latest commit has the definitive filter for the subset of behaviour instances whose script id is of the metadata automation category. |
Well done, it seems to work very well now:
For the last three cases, I assume that no messages are available that would make it possible to reflect changes immediately, is that correct? I'm wondering if a daily update job would make sense, WDYT? |
...b.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java
Outdated
Show resolved
Hide resolved
|
@jlaur of course the event resources only contain partial data so the script id is missing which means that the new filter was not satisfied so the events were not actually being processed at all. |
Signed-off-by: AndrewFG <software@whitebear.ch>
@jlaur today's commit fixes the open issues mentioned below, so I think it is now (finally) ready to go.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
today's commit fixes the open issues mentioned below, so I think it is now (finally) ready to go.
Cool work! I've also re-run my tests, and everything seems to work really well (and fast) now.
I have added a few comments to the code.
...ding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/enums/ContentType.java
Outdated
Show resolved
Hide resolved
...ding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/enums/ContentType.java
Outdated
Show resolved
Hide resolved
....openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Event.java
Outdated
Show resolved
Hide resolved
...b.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: AndrewFG <software@whitebear.ch>
@jlaur the Maven build now shows some warning messages (see below) .. which (as far as I can tell) are due to #16875 .. however I am not sure if I can fix them here, or if @lsiepel should look at it..
EDIT: applying Line 637 in 95a964c
Line 482 in 95a964c
|
I noticed them as well. I think it would be better to address them in a separate PR to not extend the scope of this PR. |
Yeah. I already tried "jumping through hoops" to modify the code so it does not create compiler warnings .. however the only thing that I could find that "works" was @SupressWarnings ;) => so I am more than happy to defer to someone more knowledgeable about this issue.. |
Created a PR here: #17293 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch> Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
Add support for enabling automations
Closes #16904
Signed-off-by: Andrew Fiddian-Green software@whitebear.ch