Nest Binding is available for Openhab1. I am porting it according to the new concepts of Openhab2 (or Eclipse Smarthome). I have implemented everything from constructing thing, mapping Java objects to JSON, updating state and status of channel and handling commands.
Now, I am stuck at creating new items. Number of devices is not a constant number, so I need to create new channels according to the devices and sensor data coming. There’s no issue with that. Problem is when I need to create new items. I need to dynamically generate new items and link them to channels. I could not find any documentation on creating new items. I am thinking of directly updating the items file. What is the best approach to do so or is there some alternative?
I do not want to hard code anything.
I am not familiar with the Nest binding, but in general, no binding should ever create items by itself - you will hence also find no documentation about that
I need to create new items because there can be any number of devices.
Items are not linked to channels automatically. In OH1, you have to mention the link in .items file and in OH2, you can add the link by calling REST APIs.
PUT /items/{itemname} for adding new item
PUT /links/{itemName}/{channelUID} for linking item and channel
But I think they are not shown in ItemRegistry. We need to add them to registry if we want handleCommand to work like for any other item created. Am I right?
What are “they”? All items that the user declares in the items-file are certainly in the item registry. And all items that are linked to a channel of the Nest-Thing, will make the handleCommand called.
But I cannot query them using Rest API. GET /rest/items is only giving me items which I added using api only but not from items-file. Additionally, when I try to change the value of item (defined in items-file) using Classical UI, handleCommand is not called and console gave me error that item is not in registry.
So I thought that items in items-file are not in item registry because dynamically generated items (from Rest API) did not give me such error. Where did I do wrong if it is not the case?
I would assume that you have some syntax error in your item file so that it is not correctly parsed.
I have just tried the latest OH2 demo build and I see all items from demo.items on the REST API:
If your binding requires that items are defined, you’ve taken a wrong turn in reaching that point. Also, HVAC mode is not an OnOffType, so it makes no sense to try to toggle it.
I would be so happy if I had the opportunity to port this binding. I’m actually quite proud of it (I know, pride is a sin).