Aeon Labs Smart Energy Switch – Reading Values

Posted on
Mon Feb 15, 2016 11:04 pm
canalrun offline
Posts: 80
Joined: Jan 17, 2016

Aeon Labs Smart Energy Switch – Reading Values

The Aeon Labs Smart Energy Switch provides the current wattage being consumed.

In Indigo when I click on this device it shows the current wattage consumed within the values shown at the bottom of the window.

How do I read this value in Python and assign it to a variable.

There are some similar examples given in the documentation, but I don't see where it is described how to get the desired parameter name or list of parameters available.

The closest I've seen is an example for sending an email. Rather than send an email I would just use the value obtained:

Code: Select all
# Putting device data into the subject and body
theDevice = indigo.devices[980532604]
theSubject = "Summary of %s" % (theDevice.name)
theBody = "%s is %s\n%s is %s" % ("onState", str(theDevice.onState), "lastChanged", str(theDevice.lastChanged))
indigo.server.sendEmailTo("emailaddress@company.com", subject=theSubject, body=theBody)


Using the above code as an example, how would I find out the list of item values available: such as onState and lastChanged?

Another example: In a few days, I should receive a Zipato multi sensor. This. Includes an ambient light detector. How would I go about finding the name of the parameter which corresponds to the Lux value of detected ambient light?

Thanks,
Barry.

Posted on
Tue Feb 16, 2016 5:07 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Aeon Labs Smart Energy Switch – Reading Values

Hi Barry - first, you can see the device's states by looking at the list at the bottom of the device profile (you might have to scroll to see them):
Screen Shot 2016-02-16 at 4.52.55 AM.png
Screen Shot 2016-02-16 at 4.52.55 AM.png (35.71 KiB) Viewed 2515 times

You can copy any one of them by right-clicking and selecting copy Python reference, which will give you something like this (The bit after the hashtag is just a label and can be ignored):
Code: Select all
indigo.devices[1149686816].states["temp"] # State "temp" of "London Weather"

This shows you how to refer to Device States in Python. To do the same for a variable, create your variable, right-click and select Copy Python Reference, and you get this:
Code: Select all
indigo.variables[1961258112] # "Foo01"

Then it's just a matter of putting the two together in a Python Script:
Code: Select all
# Get the target value:
theTemperature = indigo.devices[1149686816].states["temp"]

# To set the variable value equal to the device state value, we use the "update value command". 
# SPECIAL NOTE: Indigo variables are always strings (text) so you need to change the value to
# something that can be saved in a variable.  If something's already a string, there's no harm
# done, but if something is a number, this will be required:
theTemperatureString = str(theTemperature)

# Finally, we can save it:
indigo.variable.updateValue(1961258112, value=theTemperatureString)

You can learn more about working with variables here: http://wiki.indigodomo.com/doku.php?id=indigo_6_documentation:variable_class
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Feb 16, 2016 8:37 am
canalrun offline
Posts: 80
Joined: Jan 17, 2016

Re: Aeon Labs Smart Energy Switch – Reading Values

Thanks much!

Posted on
Tue Feb 16, 2016 8:59 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Aeon Labs Smart Energy Switch – Reading Values

You bet. Let me know if you have any questions.


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Feb 16, 2016 2:28 pm
canalrun offline
Posts: 80
Joined: Jan 17, 2016

Re: Aeon Labs Smart Energy Switch – Reading Values

Success! Thanks.

When I right clicked on the device in Devices it copied the device reference, but I could see no way of having it list the possible device state variables:

indigo.devices[1002171939] # "BR Smart Energy Switch (DSC06106)"


I opened a Python Shell and issued the following command:

>>> indigo.server.log(str(indigo.devices[1002171939].states))


I received the following output in the log:

Interactive Shell States : (dict)
accumEnergyTimeDelta : 0 (integer)
accumEnergyTimeDelta.ui : 0 seconds (string)
accumEnergyTotal : 0.007 (real)
accumEnergyTotal.ui : 0.007 kWh (string)
curEnergyLevel : 0 (real)
curEnergyLevel.ui : 0.000 W (string)
onOffState : off (on/off bool)


I then issue the command:

>>> indigo.server.log(str(indigo.devices[1002171939].states['curEnergyLevel']))


and received:

Interactive Shell 0.0


which is the proper value since nothing is plugged in.

I'm guessing that status reading output fetches and shows the current status.

Do I need to issue a command to update the status before I request the reading?

Barry.

Posted on
Tue Feb 16, 2016 3:48 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Aeon Labs Smart Energy Switch – Reading Values

Welcome to the power of scripting in Indigo! You don't need to issue a command to update the status of the device before you query it. You'll get the current value that Indigo knows about.

But there's more that you can do, as well. We've looked at device states, but Indigo knows a lot more about your device. If you issue the command without '.states' at the end, you'll get the full dictionary of properties stored for the device (like so):

Code: Select all
indigo.server.log(str(indigo.devices[761255781]))

There, you can see all the device states (which you've already figured out) but you'll also see the device's properties. You can access the value of the device's properties thusly:
Code: Select all
indigo.server.log(str(indigo.devices[761255781].model))

indigo.server.log(str(indigo.devices[761255781].name))

indigo.server.log(str(indigo.devices[761255781].sensorValue))

and so on.

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron