is it possible to change device type in plugin

Posted on
Sun Apr 19, 2020 9:30 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

is it possible to change device type in plugin

I like to change
<Device type="dimmer" id="xxx">
to
<Device type="relay" id="xxx">
from within the plugin for a specific device. Is there any way to do that?

If not, is there a way to switch off the brightness bar in the device display for a dimmer device?
Screen Shot 2020-04-19 at 10.30.14.png
Screen Shot 2020-04-19 at 10.30.14.png (15.31 KiB) Viewed 821 times

Thanks

Karl

Posted on
Sun Apr 19, 2020 12:39 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: is it possible to change device type in plugin


Image

Posted on
Mon Apr 20, 2020 11:59 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: is it possible to change device type in plugin

yes that works fine.

BUT it has to executed outside of validateDeviceConfigUi()

have 2 device types:
1. relay shelly relay 2.5
2. dimmer (for a shelly 2.5 used as roller device)
switching between them works flawlessly,

steps:
1.Setting a parameter in device edit in relay: mode = roller
2. in validateDeviceConfigUi() add an action item to a list (self.deviceActionList.append({"devId":dev.id,"action":"changeDeviceTypeId","value":"--new device type--"})
3. in regular thread loop check if deviceActionList is not empty
3.a if not empty do a loop through actions: dev = indigo.device.changeDeviceTypeId(indigo.device[action["devId"], action["value"])

Karl
Last edited by kw123 on Mon Apr 20, 2020 4:35 pm, edited 1 time in total.

Posted on
Mon Apr 20, 2020 1:49 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: is it possible to change device type in plugin

Why not do it in

Code: Select all
closedDeviceConfigUi(self, valuesDict, userCancelled, typeId, devId)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Apr 20, 2020 1:52 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: is it possible to change device type in plugin

Or you might use a variant of something I had to do in the Ecobee plugin:
Code: Select all
            if device_type in ['athenaSmart', 'apolloSmart', 'nikeSmart', 'vulcanSmart']:        # Supports linked remote sensors
           
                remotes = thermostat.get("remotes")
                self.logger.debug(u"{}: {} remotes".format(dev.name, len(remotes)))
               
                # Hack to create remote sensors after closedDeviceFactoryUi has completed.  If created here, they would automatically
                # become part of the device group, which we don't want.
                if valuesDict["createRemotes"] and len(remotes) > 0:
                    delayedCreate = threading.Timer(0.5, lambda: self.createRemoteSensors(dev, remotes))
                    delayedCreate.start()
               
                else:
                    self.logger.debug(u"{}: Not creating remotes".format(dev.name))
                           
            dev.replacePluginPropsOnServer(newProps)


Code: Select all
    def createRemoteSensors(self, dev, remotes):

        self.logger.debug("{}: createRemoteSensors starting".format(dev.name))
        remote_ids = indigo.Dict()

        for code, rem in remotes.items():

            for rdev in indigo.devices.iter("self"):
                if rdev.deviceTypeId == 'RemoteSensor' and rdev.address == code:    # remote device already exists
                    self.logger.debug(u"Remote sensor device {} already exists".format(rdev.address))
            else:

                remote_name = "{} Remote - {}".format(dev.name, rem["name"])
                self.logger.info(u"Adding Remote Sensor '{}' to '{}'".format(remote_name, dev.name))
                newdev = indigo.device.create(indigo.kProtocol.Plugin, address = code, name = remote_name, folder=dev.folderId,
                            deviceTypeId="RemoteSensor", props={ 'SupportsSensorValue': True, 'SupportsStatusRequest': False, 'account': dev.pluginProps["account"] })
                newdev.model = dev.model
                newdev.subModel = "Remote"
                newdev.replaceOnServer()
                newdev.updateStateImageOnServer(indigo.kStateImageSel.TemperatureSensor)
                remote_ids[code] = str(newdev.id)

        newProps = dev.pluginProps
        newProps["remotes"] = remote_ids
        dev.replacePluginPropsOnServer(newProps)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests