alexander-vitishchenko / hc3-to-mqtt

Fibaro HC3 integration with Home Assistant & NodeRed
MIT License
31 stars 13 forks source link

Selective device import #24

Closed MomosX closed 1 year ago

MomosX commented 2 years ago

Hi Alexander:) Hope you are ok and settled well in Berlin. Crazy times we live now....

I have a question: it might already be possible but i did not find out how.
How could i set the QA to just export into HA some devices , not all? or even more specific only some device properties. I have 126 devices and 433 entities in HA from HC3. I do not need all those entities and/or devices. I was thinking about impementing in the QA a list of devices id and a list of properties. If nothing is set in the list then all would be exported, else follow the list. Or in the varibles tabs. Would that be feasible please?

Regards

alexander-vitishchenko commented 1 year ago

Hi @MomosX

Wish I could do commercial Smart Home installations in Germany, this would be great, especially if I find people who need it :-) This will help earn money for a better living.

As for the filter functionality, it could be easily added to main.lua => function QuickApp:discoverDevices()

I'm thinking about exposing devices filter as a new Variable to the QuickApp, so this could be used by anyone without the need to look at the code.

Or alternatively, you can add new filters directly to the code " fibaroDevices = getFibaroDevicesByFilter({ enabled = true, visible = true }) "

Let me know your preference.

MomosX commented 1 year ago

Really good to hear back from you ! Glad at least you finally got settled and out of harm's way.
I'm sure Germany is a big market for automations and a smart person should have no trouble finding ways to make a good living, just takes a lot of patience.

Regarding the filters: if you wanna keep it friendly and for all kind of users the filters should be set in variables. But i think there should be more then one. If variable is left empty then it will assume "All", if variable is not empty the it should filter by it. One filter should be device ID - for those who just want to import a few. Another filter could be device class, another a specific property. Usually with these kind of things, the more granularity you have the better. Also there should be a "yes/no" filter to display warnings for non implemented devices or not - so the log can be kept clear if one so chooses.

Regards:)

alexander-vitishchenko commented 1 year ago

Hi @MomosX

1) Ok, let's make filtering functionality accessible for everyone, and I'll be adding a QuickApp variable in JSON format, so anyone can put any filter criteria on the top of the defaults 2) And it makes sense to filter log messages too. I just need to convert some of debug messages to trace level at first, for being able to track those debug messages that help users diagnose how QuickApp works. Then adding log level filter

MomosX commented 1 year ago

super:)

alexander-vitishchenko commented 1 year ago

@MomosX

Just to keep you updated - already working on the implementation

I've sticked to the existing Fibaro API, without reinventing the wheels.

Feel free to familirize yourself with "fibaro:getDevicesId(filters)" at https://manuals.fibaro.com/content/other/FIBARO_System_Lua_API.pdf, and they use Swagger to test if this approach works for you?

MomosX commented 1 year ago

If you are going the API way, then things should be pretty clear and even more, granularity could be very high. You could filter by id, roomID, enable, visible, different interface types and different properties. Could even filter by categories or whatever else. There should also be some sort of failback in case the filter returns nil or something else breaks it.

MomosX commented 1 year ago

For example: Filter only by type: com.fibaro.binarySwitch , visible, enabled or Filter by an id array {23,27,178,230} or Many options :) but personally i think that id, type, roomID are the most powerfull ones that should cover 80+% of the user cases Id is great when you have a few devices, type works very well when there a many devices and roomID is somehow in between. And of course any combinations of the above

alexander-vitishchenko commented 1 year ago

@MomosX - done

I've implemented support for custom device filters used for the auto discovery, and updated README.md

Can you please check how easy is to use that docs, and if filtering functionality works for you?

MomosX commented 1 year ago

Great news ! which part of the QA needs updating ?

alexander-vitishchenko commented 1 year ago

I'd generally recommend to update all *.lua files with each release of the QuickApp :-)

For this specific update - you need to update main.lua, device_api.lua and tools.lua

MomosX commented 1 year ago

ok. so maybe i'm blind but : i have updated all LUA files and i can not find where to enter the filters. I also tried to upload the entire QA but it fails with a 500 error . Did you downloaded it encrypted or something ?

MomosX commented 1 year ago

ah found it lol. testing now

MomosX commented 1 year ago

ok, can't get it to work. created a filter image

Error: unexpected symbol near '[[ { in line 407.

I also noticed there are some Overrides a few lines before. Those are taken into account anyhow , right ? Filter should consider those overrides or not ?

alexander-vitishchenko commented 1 year ago

Hi @MomosX

The filters are set with a new QuickApp variable. No lua coding required by users.

This is the example from README.me file that I mentioned before

image

MomosX commented 1 year ago

well like i said i can not upload the QA. it crashes with the error 500. Now i see the name of the variable :)

MomosX commented 1 year ago

my filter would be like: {"filter":"baseType", "value": ["com.fibaro.binarySwitch","com.fibaro.FGWP","com.fibaro.FGR","com.fibaro.actor","com.fibaro.multilevelSwitch","com.fibaro.sensor","com.fibaro.doorWindowSensor"]}

But this does not fit in the variable because of length.

MomosX commented 1 year ago

ok tried a simpler one:

{"filter":"baseType", "value": ["com.fibaro.actor"], ["com.fibaro.binarySwitch"]}

it works but filters only by Actor.

alexander-vitishchenko commented 1 year ago

Sure, you need to provide a set of values within the square brackets.

{"filter":"baseType", "value": ["com.fibaro.actor", "com.fibaro.binarySwitch"]}

P.S.: If was working for Fibaro... I would name the "value" property as "values", so it would be easier for people like you and me to understand how to use the API

MomosX commented 1 year ago

image

image

not working. no idea why :(

alexander-vitishchenko commented 1 year ago

Can you please send me JSON for those devices you expect to see? I can test it with my setup quickly, after electricity in restored at my remote Kyiv lab

Plus, we can overcome the limitation of QuickApp variable length by allowing to setup filters in multiple variables for each discovery criteria, like deviceFilter1, deviceFilter2 ... deviceFilterX?

alexander-vitishchenko commented 1 year ago

By the way - how do you like the idea to have Discord channel created for you and other Quick App users so we can improve the interactive dialog and community members can help each other in a future?

MomosX commented 1 year ago

If i set the filter individually, for only com.fibaro.actor or only com.fibaro.binarySwitch i see the devices.

image

image

image

as soon as i mix them i get 0 devices

alexander-vitishchenko commented 1 year ago

My experience with filters is the following:

Does it work same for you, of different?

MomosX commented 1 year ago

To be honest i spent the last hour trying to replicate the filters in swagger.

No matter what i do i can not combine them.

This works in swagger: {"filters": [{"filter": "type", "value": ["com.fibaro.FGR223"]}],"attributes": {}}

But adding any other value just returns [] in response, which leds me to belive it acts like AND if i put multiple values.

Even the filter {"filter":"type", "value": ["com.fibaro.FGR223","com.fibaro.FGWP101"]} that you mention in the logs returns 0 devices.

MomosX commented 1 year ago

I do not know if you seen this https://www.fibaro.com/dev/specs/hc3/

but i think the answer is somewhere in there. However, it is above my paygrade :(

alexander-vitishchenko commented 1 year ago

Let me test how your filters work with my setup.

Fibaro Filter API may have its own challenges to learn... but recreating the filter engine might be more complex, and produce a duplication from the architecture point of view.

I suggest us to raise a defect in Fibaro HC3 bug tracking system, so they fix the issue(s) eventually.

alexander-vitishchenko commented 1 year ago

By the way - fixed error 500 while uploading the QuickApp to Fibaro HC3

MomosX commented 1 year ago

Juat had an ideea to go around the limitations of the API filter. What if there are lets say 3 valiables for filters, enter in each one a different filter and then just sort it out in the code? Filter by the first variable, make the table , filter the table by the second and so on. Would that be complicated ?

alexander-vitishchenko commented 1 year ago

Yes, and this is similar to what I suggested several days ago, by using unlimited number of variables :-)

image
MomosX commented 1 year ago

pfffiuu i missed that part :( would be great !!! waiting anxiously to test :)

alexander-vitishchenko commented 1 year ago

By the way have you succeeded with Fibaro Filter API and it works for you as expected on small number of filters?

MomosX commented 1 year ago

on one filter "type" works very well yup

alexander-vitishchenko commented 1 year ago

Implemented support for lengthier device filters, and overcame Fibaro QuickApp limitations by using "deviceFilter", "deviceFilter1", "deviceFilter 2" ... "deviceFilterX" naming convention