Skip to main content



      Home
Home » Archived » Eclipse SmartHome » change states of a channel
change states of a channel [message #1778076] Sat, 09 December 2017 03:53 Go to next message
Eclipse UserFriend
hi,

I want to change state values of a channels (e.g. like in YamahaZoneThingHandler.java from yamahareceiver binding).

That's my channel and channel-type:
...
<channel id="movepreset" typeId="movepreset-channel" />
...
<channel-type id="movepreset-channel">
   <item-type>String</item-type>
      <label>Move to preset</label>
      <description>Moving to preset</description>
      <state pattern="%s">
         <options>
		<option value="HOME">home</option>
	</options>
     </state>
</channel-type>
....


That's my code to cahnge the states:
    protected void thingStructureChanged() {

        final ChannelTypeUID channelTypePresetUID = new ChannelTypeUID(
                MyBindingConstants.BINDING_ID, "movepreset-channel");
        
        ChannelType templateType = TypeResolver.resolve(channelTypePresetUID);

        List<StateOption> options = new ArrayList<>();
        options.add(new StateOption("TEST1", "Test 1"));
        options.add(new StateOption("TEST2", "Test 2"));

        StateDescription state = new StateDescription(null, null, null, "%s", false, options);

        ChannelUID movepresetChannelUID = new ChannelUID(thing.getUID(), "movepreset");
        
        ChannelTypeUID channelTypeUID = new ChannelTypeUID(movepresetChannelUID.getAsString());
        ChannelType channelType = new ChannelType(channelTypeUID, false, "String", templateType.getKind(),
                templateType.getLabel(), templateType.getDescription(), templateType.getCategory(),
                templateType.getTags(), state, templateType.getEvent(), templateType.getConfigDescriptionURI());
        
        Channel channel = ChannelBuilder.create(movepresetChannelUID, "String").withType(channelTypeUID).build();
        
        // Remove the old channel and add the new channel            
        updateThing(editThing().withoutChannel(movepresetChannelUID).withChannel(channel).build());
    }


The original channel seems to be removed and a new empty channel was added.
In PaperUI it looks like that:

index.php/fa/31528/0/

when I click on it:
index.php/fa/31529/0/

I don't understand it! Can anyone explain to me what I'm doing wrong?




  • Attachment: paperui1.jpg
    (Size: 3.89KB, Downloaded 562 times)
  • Attachment: paperui2.jpg
    (Size: 4.48KB, Downloaded 561 times)

[Updated on: Sat, 09 December 2017 03:54] by Moderator

Re: change states of a channel [message #1778170 is a reply to message #1778076] Mon, 11 December 2017 08:20 Go to previous messageGo to next message
Eclipse UserFriend
is there anything else what I missed with the created channeltype???
 ChannelType channelType = new ChannelType(channelTypeUID, false ...


for testing I add ".withLabel(..." to create call
Channel channel = ChannelBuilder.create(movepresetChannelUID, "String").withType(channelTypeUID)
                .withLabel("Test label").build();


the label is added probaply to the channel:
index.php/fa/31543/0/

I don't get it!
  • Attachment: paperui3.jpg
    (Size: 4.00KB, Downloaded 589 times)
Re: change states of a channel [message #1778328 is a reply to message #1778170] Wed, 13 December 2017 02:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi Nils,

instead of adding/removing channel types and channels you should implement your own ConfigDescriptionProvider. With this you can dynamically change the config options provided for a specific channel type.

Hope that helps. Cheers
Henning

Re: change states of a channel [message #1778417 is a reply to message #1778328] Thu, 14 December 2017 01:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi Henning,

thank you for your response. I've just seen this the ConfigDescriptionProvider yesterday.
I will give it a try.
Re: change states of a channel [message #1779080 is a reply to message #1778417] Tue, 02 January 2018 04:50 Go to previous messageGo to next message
Eclipse UserFriend
hi Henning,
happy new year!
I've tried now but can't get it work. i've implemented an OptinonProvider which imlpements ConfigDescriptionProvider, ConfigOptionProvider (like Chris in his zwave binding). I create the xml configuration for this OptionProvider In OSGI-INF.
When I start openhab the OptionProvider is only called for my bridge properties but not for my thing with the channels.
Have you an idea what I doing wrong?
Re: change states of a channel [message #1791055 is a reply to message #1778328] Fri, 22 June 2018 05:14 Go to previous messageGo to next message
Eclipse UserFriend
after a long break I try it again but without success.

In PaperUI it looks like:

because of the default channel definition in my thing.xml.
index.php/fa/33201/0/
I want that the presets are dynamic loaded from a server:
index.php/fa/33202/0/

How can I change the options at runtime? Can you give me a simple example?

  • Attachment: preset1.jpg
    (Size: 12.34KB, Downloaded 336 times)
  • Attachment: preset2.jpg
    (Size: 13.85KB, Downloaded 374 times)

[Updated on: Fri, 22 June 2018 05:15] by Moderator

Re: change states of a channel [message #1791078 is a reply to message #1791055] Fri, 22 June 2018 08:46 Go to previous messageGo to next message
Eclipse UserFriend
... I think I mess things up ...

the ConfigDescriptionProvider seems not to be the right choice for that!
Re: change states of a channel [message #1791638 is a reply to message #1791078] Tue, 03 July 2018 04:39 Go to previous messageGo to next message
Eclipse UserFriend
Hello Nils,

thank you for not giving up yet! I am pretty sure we will manage to get your problem solved.

I guess what you need is a ConfigOptionProvider as an OSGi service, like implemented in our magic testing bundle:

https://github.com/eclipse/smarthome/blob/2c0d330532c898bd7e26815e38d8715de87f8f32/bundles/test/org.eclipse.smarthome.magic/src/main/java/org/eclipse/smarthome/magic/binding/internal/MagicServiceImpl.java#L44-L57

Regards,

Stefan
Re: change states of a channel [message #1791650 is a reply to message #1791638] Tue, 03 July 2018 06:23 Go to previous messageGo to next message
Eclipse UserFriend
Hello Stefan,

thank you for your answer and your help.

In the meantime I found a solution. I used a DynamicStateDescriptionProvider. For all who are interested
-> that's my implementation: https://github.com/nibi79/synologysurveillancestation/blob/master/src/main/java/org/openhab/binding/synologysurveillancestation/internal/discovery/SynoDynamicStateDescriptionProvider.java

Thanks again!
Re: change states of a channel [message #1791663 is a reply to message #1791650] Tue, 03 July 2018 09:45 Go to previous message
Eclipse UserFriend
Hello Nils,

glad you found a solution. I was actually on the wrong track with configurations...

Are you planning to create a PR to ESh or openhab2-addons with your new binding? Would be cool to see it as a contribution!

Regards,

Stefan
Previous Topic:ESH Google IoT core binding
Next Topic:Gather the data from channels
Goto Forum:
  


Current Time: Tue May 13 16:40:29 EDT 2025

Powered by FUDForum. Page generated in 0.04936 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top