Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
jgab 1,956
-There is always this issue with device IDs needed to be declared in the header. Then a device is reincluded and gets a new id and code breaks.
-Then there is the issue of an integer being a bad way to refer to devices when coding and thus we build hometables or declare variables.
This code is an example of trying to solve both issues. It works but is more of a concept for the moment as some more checks and more type of triggers need to be supported. (It supports value, power,sceneActivity and simple CentralSceneEvent for now)
Anyway, we have a scene that builds a "hometable", lets call it the "HomeTableBuilder". It builds the table from meta data stored in the 'Device description' field for devices (not for virtual devices, they don't have a description field and they don't trigger scenes anyway).
The format is very flexible to specify where in the home table 'tree' the deviceId should be inserted..
Please login or register to see this attachment.
'Device description' = ["dev.%room.tableLamp.%id"]
will set HomeTable.dev.kitchen.tableLamp=417, if the device is in room 'kitchen' and has id 417
'Device description' = ["dev.%section.%room.tableLamp.%id"]
will set HomeTable.dev.upstairs.kitchen.tableLamp=417, if the device is in section 'upstairs' and room 'kitchen' and has id 417
'Device description' = ["dev.remote.%id"]
will set HomeTable.dev.remote=362, if the device is a fibaro remote with id 362
The code in the HomeTableBuilder that needs to be setup is:
Please login or register to see this code.
So this take care of creating a hometable (HT in the code) from meta data stored in the devices themselves. We can then add more static configuration data to the hometable etc.
After that we declare which of our other scenes should receive events. (Test1 has id 313, and Test2 has id 316 in this example). sceneId(string) is a convenience function to get the ID from a scene name.
Please login or register to see this code.
This says that we want to receive property.value events from "tablelamp" and send it to the scenes named "Test1" and scene named "Test2"
We declare the same for "power"
And our fibaro remote should send its events to "Test1" and "Test2" too.
The HomeTableBuilder then dynamically creates another scene in the HC2 named "EventProxy"..softwareVersion. (it's always created hidden for me!?, do "show hidden")
with the following code:
Please login or register to see this code.
This "EventProxy" scene receive triggers for the devices declared and send them to the scene we declared having interest in these events, Test1 and Test2 in this case.
The code in a receiving scene (like Test1) then looks like below. (No declared triggers in the header, it gets all triggers from startScene from the EventProxy)
Please login or register to see this code.
Scenes should still declare globals, weather etc... triggers that are not connected to devices IDs.
So, what have we achieved?
-We don't have to deal with numerical device IDs in our code
-We can add meta data to devices that tells where in the HomeTable they should be inserted
-We don't have to declare numerical IDs in headers
Drawback: A small performance penalty to let the EventProxy trigger other scenes instead of they being triggered directly. (Seems to be very small penalty though, logs are always on the same second in EventProxy and receiving scenes for me). One could generate different EventProxy scenes for different triggers to distribute the load a bit and ensure that the EventProxy doesn't hit the maximum 10 active instances... However, an activated EventProxy instance is very quick to dispatch the event and then terminate.
Improvement: Let scenes dynamically register which events they want when they start up. Only issue is how often the EventProxy need to be rebuilt...
Code for the complete HomeTableBuilder:
Please login or register to see this code.
Link to comment
Share on other sites
Top Posters For This Question
36
11
3
2
Popular Days
Dec 10
10
Dec 9
8
Aug 16
6
Dec 17
4
Top Posters For This Question
jgab 36 posts
jompa68 11 posts
petergebruers 3 posts
ipsofacto 2 posts
Popular Days
Dec 10 2017
10 posts
Dec 9 2017
8 posts
Aug 16 2018
6 posts
Dec 17 2017
4 posts
Popular Posts
jgab
-There is always this issue with device IDs needed to be declared in the header. Then a device is reincluded and gets a new id and code breaks. -Then there is the issue of an integer being a bad
jgab
With your own sense of time (the code uses a defined osTime() instead of os.time) it is quite easy to adjust the drifting clock on the HC2 - mine is 417 secs behind at this moment. Hopefully Fibaro wi
tinman
one can emulate 'CentralSceneEvent' event trigger (but there is more, e.g. 'SceneActivationEvent', 'accessControlEvent', 'VideoGateIncomingCallEvent' ... but not yet implemented in that script below.)
Posted Images
56 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.