Jump to content

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


  • 0

Plugin Development: How to add a devices selector for configuration.


Question

Posted (edited)

Hi,

 

A common challenge for a plugin is to select another device to interact with.

 

I have used this for my Samsung TV plugin to select a zwave switch that turns the TV off at the mains rather than putting it to sleep. This is more useful than the standard plugin device as putting the TV to sleep turns off the network so that HC2 has no contact and the device can not be turned on again. Turning of at a mains switch using zwave reduces the energy consumption to less  the standby but the TV turns back on when mains is returned and can be controlled again. This makes TV scenes etc much more capable as they can control the TV fully.

 

Not sure what the new plugin framework will look like but for the current this is how it works.

 

There are four files to edit:

 

1) add the property to the type file yourplugin.xml to hold the device id that you want to use in your code

 

Please login or register to see this code.

I have set the default to -10 so that the code that controls it can check if it is set.

 

2) add to the configuration view field config.xml. Note the name of the property and the name of the selector are the same for clarity.

Please login or register to see this code.

3) Make sure main.lua is configured correctly there are two important sections

The first you need anyway to make use of actions on the plugin devices but make sure to return the result. I did not do this and wasated an hour figuring out my mistake.

Please login or register to see this code.

the second is the section responsible for saving the configuration values in the properties

 

Please login or register to see this code.

This catches the save when editing properties in the configuration page.

 

4) add the function to your yourplugin.lua file that is your class file for your plugin. Note: getSwitchDevices is the onload property of the control.

Please login or register to see this code.

lastly use the device in your plugin. In this case the turn amplifier on and off from my squeezbox player plugin

Please login or register to see this code.

When I have tested the full plugins I will make them available to those interested.

 

I hope the new framework is as good as this when it comes. All that is missing from this one might be documentation. Also you do need to be careful that you trust the code that you load.

 

I hope this gives you the inspiration to try for yourself.

 

Robert 

Edited by robmac

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...