get StateOnServer

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
contrast
Posts: 11
Joined: Thu Feb 26, 2009 12:09 pm
Location: Switzerland
Contact:

get StateOnServer

Post by contrast »

Hello

if there a Way to get the State of a plugin Device???

I try to write a plugin to control my Nuvo Essentia.
I need to get the State "zoneOnOff" of my Device to Toggle Power On and Off
or if there another way to do toggle my deviceState "zoneOnOff

my Problem --->
---> if StateOnServer((key="zoneOnOff") = True):
MESSAGE = MESSAGEZoneStart + zone + "OFF" + MESSAGEEnd
self.sendUDP(MESSAGE, dev, logMessage)
dev.updateStateOnServer(key="zoneOnOff", value=False)
else:
MESSAGE = MESSAGEZoneStart + zone + "ON" + MESSAGEEnd
self.sendUDP(MESSAGE, dev, logMessage)
dev.updateStateOnServer(key="zoneOnOff", value=True)

pleas help me, i use indigo a long time but plugin programming and Python is new for me...
English is not my native language --> sorry :cry:
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: get StateOnServer

Post by jay (support) »

You get the states when you get the device object from the server:

Code: Select all

# Get the opposite boolean value of zoneOnOff's current value
newValue = not dev.states["zoneOnOff"]
# Create the appropriate message - ON if true OFF if false
if newValue:
    MESSAGE = MESSAGEZoneStart + zone + "ON" + MESSAGEEnd
else:
    MESSAGE = MESSAGEZoneStart + zone + "OFF" + MESSAGEEnd
# Send the message
self.sendUDP(MESSAGE, dev, logMessage)
# Update the state
dev.updateStateOnServer(key="zoneOnOff", value=newValue)
If the dev object is old and may not contain up-to-date values, use dev.refreshFromServer() to get it updated.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
contrast
Posts: 11
Joined: Thu Feb 26, 2009 12:09 pm
Location: Switzerland
Contact:

Re: get StateOnServer

Post by contrast »

woooow thx for very fast Answer

why i try a lot of hour before i write here for Help :?
contrast
Posts: 11
Joined: Thu Feb 26, 2009 12:09 pm
Location: Switzerland
Contact:

Re: get StateOnServer

Post by contrast »

next problem--

is it possible to updateStateOnServer(key='zoneMute', value=True) in all my devices from same plugin

thx for help
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: get StateOnServer

Post by jay (support) »

Sure - something like this:

Code: Select all

for dev in indigo.devices.iter("self"):
    dev.updateStateOnServer(key='zoneMute', value=True)
The docs about built-in objects describe iterators.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
Locked

Return to “Extending Indigo with Plugins and Python”