Update server state action

Posted on
Wed Apr 10, 2013 1:07 pm
krissh offline
Posts: 105
Joined: Nov 18, 2012
Location: Norway

Update server state action

Again, thanks for a great plugin :)

Could I kindly to ask you to include an action to update server state in your next release?
Usage example 1:
I have mostly Nexa dimmer (AC Dimmer). These can be programmed with up to six codes. I've programmed all of mine with three codes from RFXCOM; 1) Direct, 2) Group, 3) All lights. This enables me to control a group (say living room) of lights with one RF command, which is a lot faster, and I can turn on/off all lights instantly, which is kind of neat. Turning them off one by one takes maybe 20-25 seconds. But I would still like to keep server state "up to date", without actually sending the same command to all dimmers.

Usage example 2:
I have some remotes/wall switches which are controlling the dimmer directly. Indigo can see the command from the remote, so what I'm doing today is sending the same command (again) from Indigo (to udate server state), which I feel is a bit unnecessary.

I've tested the following code successfully, and hope that you can include it (I'm sure some competent review of this code could be useful :lol: )

plugin.py:
Code: Select all
   ########################################
   def updateState(self, action):
      self.debugLog(u"updateState action called")
      if action.deviceId != 0:
         try:
            devtmp = indigo.devices[action.deviceId]
         except:
            self.errorLog(u"Invalid device specified in updateState action")
         
      if "onOffState" in action.props:
         # Update server on/off state
         stateValue = action.props.get(u"onOffState")
         if stateValue == "on": stateValue = True
         if stateValue == "off": stateValue = False
         if (stateValue == True or stateValue == False) and stateValue != "nochange":
            self.debugLog(u"    Update server On/Off state for device id %s with %s" % (str(action.deviceId), str(stateValue)))
            devtmp.updateStateOnServer("onOffState", stateValue)
         elif stateValue == "nochange":
            self.debugLog(u"   Update server On/Off state for device id %s - No Change" % str(action.deviceId))
         else:
            self.errorLog(u"Invalid On/Off state specified for updateState action")

      if "brightness" in action.props:
         # Update server brightness level
         brightnessLevel = action.props.get(u"brightness")
         try:
            self.debugLog(u"Update server state BrightnessLevel: --%s--" % str(brightnessLevel))
            if brightnessLevel == "":
               self.debugLog(u"   Update server brightness level for device id %s - No Change" % str(action.deviceId))
            else:
               brightnessLevel = int(brightnessLevel)
               self.debugLog(u"    Update server brightness level for device id %s with %s" % (str(action.deviceId), str(brightnessLevel)))
               devtmp.updateStateOnServer("brightnessLevel", brightnessLevel)
         except:
            self.errorLog(u"Invalid brightness level specified for updateState action")


Actions.xml
Code: Select all
<?xml version="1.0"?>
<!-- If your plugin wants to add actions to the action step dialog that are independent
    of a device (devices define their own actions), define them here.
-->
<Actions>
   <Action id="allOff">
      <Name>All Off</Name>
      <CallbackMethod>allOff</CallbackMethod>
   </Action>
   <Action id="updateState" deviceFilter="self">
      <Name>Update State and Brightness on Server</Name>
      <CallbackMethod>updateState</CallbackMethod>
      <ConfigUI>
         <Field id="onOffState" type="menu">
            <Label>On/Off State:</Label>
            <List>
               <Option value="nochange">No Change</Option>
               <Option value="on">On</Option>
               <Option value="off">Off</Option>
            </List>
         </Field>
         <Field id="brightness" type="textfield">
            <Label>Brightness:</Label>
         </Field>
      </ConfigUI>
   </Action>
</Actions>


Picture from Action config:
Image

Python code to update server status:
Code: Select all
p=indigo.server.getPlugin("nl.rjdekok.indigoplugin.RFXCOM")
p.executeAction("updateState",deviceId=115349555,props={"onOffState":True,"brightness":81})

Posted on
Sun May 05, 2013 1:21 pm
RJdeKok offline
Posts: 125
Joined: Mar 27, 2012

Re: Update server state action

A new version is available with this action built in: http://www.rjdekok.nl/downloads/RFXCOM.indigoPlugin.zip

Posted on
Fri May 10, 2013 2:37 am
krissh offline
Posts: 105
Joined: Nov 18, 2012
Location: Norway

Re: Update server state action

Great, thanks :-)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests