Adapters Plugin [archive]

Posted on
Thu Mar 31, 2016 8:17 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Temperature Scale Adapters Plugin

If anyone wants to beta test a version that supports temperature AND length measurements, here's a link: BETA VERSION WITH LENGTH SUPPORT

I think it's working fine, though I had to do some hacking to ensure backward compatibility and I could only test that once. :) If it happens to break an existing device for you, it should fix things if you delete the device and re-add.

Once I'm a little more confident in it I'll merge the branch and release the update for reals.

Posted on
Thu Mar 31, 2016 8:22 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Temperature Scale Adapters Plugin

Actually, Matt, is there a blessed way to handle such a plugin update? The forum title, the bundle info, and the device type id all specifically refer to "temperature" even though I'm now broadening the scope of the plugin to cover other types of scales as well.

Should I start a new post, and just link to it from this one? Or ... something else?

Posted on
Sat Apr 02, 2016 7:24 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Temperature Scale Adapters Plugin

Bollar wrote:
My OCD suggests you add a space between the number and degrees to match Indigo's format.

+1 on that (I know you've already fixed it for the next release.)

I would suggest another enhancement, which would be the ability to control precision (i.e., the ability to display 37 °F, 37.0 °F, or 37.00 °F)

Thanks for the needed plugin!
Dave

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

[My Plugins] - [My Forums]

Posted on
Sat Apr 02, 2016 7:50 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Temperature Scale Adapters Plugin

Hey, just saw something else. After creating a device and saving it, all is good. Upon re-entering the device config dialog, the source device state dropdown is blank and, when selected, the originally selected state is not present in the list. If you hit cancel, the device still seems to work as intended.

Request: when you re-enter the device config dialog, have the linked state display as the current setting.

Dave

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

[My Plugins] - [My Forums]

Posted on
Sun Apr 03, 2016 8:06 am
loafbread offline
Posts: 137
Joined: May 25, 2009

Re: Temperature Scale Adapters Plugin

This is really great. This can replace lots of snippets of code I had trying to convert everything.

Now here it comes..... when you get time, how about a dew point calculation plugin :)

Thanks for your work

Posted on
Mon Apr 04, 2016 7:29 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Temperature Scale Adapters Plugin

I've pushed a new version of the plugin to GitHub with the following changes:

  1. support for length, power units in addition to temperature
  2. add a space between converted and units symbol (e.g. "25 kW") to relieve OCD-related tension
  3. fix bug where selected state disappeared from list when editing an existing device

Note: I made this as backward compatible as possible, though I did change the state name from "temperature" to "sensorValue" (since it's no longer necessarily a temperature); thus, you may have to update your control pages and such to work with the new state name. I think that's the only thing that's not backward-compatible, though I may have forgotten something.

At some point I also need to rename this plugin everywhere (in the bundle identifiers, this thread name, possibly other places) for clarity, but I'm not sure if there's an "approved" way to do that.

Good luck, and let me know how it goes!

Posted on
Wed Apr 06, 2016 8:48 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Temperature Scale Adapters Plugin

dustysparkle wrote:
Actually, Matt, is there a blessed way to handle such a plugin update? The forum title, the bundle info, and the device type id all specifically refer to "temperature" even though I'm now broadening the scope of the plugin to cover other types of scales as well.

Should I start a new post, and just link to it from this one? Or ... something else?

Good question. As long as you keep the .plist plugin ID and the device XML type IDs the same Indigo shouldn't care about the display/UI name. So even though the plugin (and device)ID references temperature I would just leave those as-is since they are not presented via UI (although I guess the device type IDs might be used in scripting....). As for the forum, I'd suggest just editing your original post on this thread to have the new name. Starting a new thread is fine as well, in which case I'd recommend locking this thread after posting a pointer to the new one, just to avoid confusion as to where question reply posts should go.

Image

Posted on
Wed Apr 27, 2016 9:04 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Scale Adapters Plugin (temperature, length, power)

I've changed the post title to reflect that the plugin now handles length and power in addition to temperature conversions.

That being said, is anyone actually using the plugin for length or power conversions? I've done some testing using fake data so I believe it works, though I'm interested in learning more about the use cases and confirming that it's working properly for reals. :-)

Posted on
Fri May 27, 2016 1:19 pm
noefresh offline
Posts: 119
Joined: Sep 10, 2013

Re: Scale Adapters Plugin (temperature, length, power)

Wow- great plugin and exactly what I was looking for!!! This should be a built in plugin. :) :)

Posted on
Fri May 27, 2016 5:58 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Scale Adapters Plugin (temperature, length, power)

question to Matt & Jay:

could we just have an option to use a regular format string with offset and multiplier . That would address any linear transformation and we could show the data in any format we like:

device.xml input:
- offset to number (offset)
- multiplier to number(multiplier)
- format string (fString)

The string displayed would be with x = original number

dev.updateStateOnServer( "status", fString %((x+offset)*multiplier) ) # if status is your state you like to show with the new format

with eg
offset =-32
multiplier 0.5555555 (=5/9)
fString = "%4.1f ºC"

would give you a temperature in C from x in Fahrenheit as e.g. 20.4 ºC


and the other way around C --> F
offset = 17.777 ( =32*5/9)
multiplier = 1.8 (=9/5)
fString= "%3d ºF"

would show temperature in whole numbers in F e.g. 73 ºF

Karl

ps if my math is right

Posted on
Fri May 27, 2016 6:52 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Scale Adapters Plugin (temperature, length, power)

I'm not positive I understand the request. Are you suggesting for a given state we not just have a single .ui variant, but allow multiple? So the end result is the user could select a device state for a temperature sensor on a Control Page, and they would have in the state popup multiple variants to choose from (both °F and °C, for ex). That is, they don't have to pre-choose C or F at all because they would both exist and could be selected when constructing the Control Page?

Image

Posted on
Fri May 27, 2016 7:06 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Scale Adapters Plugin (temperature, length, power)

add default states:

offset
multiplier
fString

To be applied to the display field.
This would cover ºF, ºC, miles, Km, Watts, kWh, mm, inches, seconds, minutes, liter, cF mL, ... anything from any number as long as the relation ship is linear.

e.g. cm --> feet
offset =0
multiplier = 0.0328 (= 1/(2.54*12))
fString = "%3.1f '" .. note the ' before the "

would show e.g. x= 33.7 measured in cm as >>1.1'<< ( = 1.1 feet)



Karl


if we want to get fancy we could add an option to show 0/1 as up/down but thats likely v8

Posted on
Sun Jun 05, 2016 8:19 pm
dustysparkle offline
Posts: 54
Joined: Dec 14, 2015

Re: Scale Adapters Plugin (temperature, length, power)

I have a new release candidate (sort of an open beta) that adds the functionality that kw123 was suggesting and more. Essentially, there are now four device types:

  1. Predefined Scale Adapters. These are the existing temperature, length, and power adapters already published. This version adds the capability to choose the precision (number of decimal places) shown, between zero and three.
  2. Custom Linear Adapter. This is what kw123 was asking for. This lets you specify an arbitrary multiplier, offset, and output format to essentially build your own adapter. For example, if the plugin didn't have temperature conversion already built in, then you could convert from Celsius to Fahrenheit by specifying multiplier=1.8 and offset=32 (since the conversion formula is F = 1.8 * C + 32). You can also write your own formatting string (using new-style Python syntax), which lets you choose the number of decimal places, add spaces between the value and the units, or whatever you may want to do.
  3. Custom Formula Adapter. This allows you to specify an arbitrary mathematical formula for the conversion, plus a format specifier. You could do the above temperature conversion example with a formula value of "1.8 * x + 32". You can also use exponents (with "**") , parentheses, and even simple if-else expressions, e.g. "x ** (1/2) if x >= 0 else (-1 * x) ** (1/2)".
  4. Custom Formula Adapter, String value. This is the same as the above, but with a string output rather than numeric. This lets you do something like "'on' if (x > 0) else 'off'".

kw123 and I have done some testing and it seems solid, but I thought I'd release an 'open beta' before officially calling it 'done'. If you want to try things out and provide feedback, it's temporarily available in a release branch here: https://github.com/jdhorne/temperature- ... ease/1.0.0

Once I an overwhelmed with warm fuzzies that it's solid, I'll close out that branch, label the result as version "1.0.0" (guess it's about time), and update the title and first post in this thread to reflect the change.

Thanks for any feedback you may have.

Posted on
Sun Jun 05, 2016 10:48 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Scale Adapters Plugin (temperature, length, power)

this is really a major step forward for the user-friendliness and adaptability of indigo. If there would be a user award I would vote for this one.
you now can transform any state of any device to any number / text and format

eg x --> sin**x +5x unit = whatever you like ; if you want to do that kind of thing.
or "up" --> "light is on"
"down" --> "door is closed"

Karl

Posted on
Mon Jun 06, 2016 12:41 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Scale Adapters Plugin (temperature, length, power)

Hi. Thank you for this plugin. I think this can simplify several things in my setup.

Can you please advice how to add a multiplier. I have a power clamp that measures power, but since I split them up I have to multiply by 4.1. When I try to do this the device shows 0..? Has this something to do with format?

Håvard

Håvard

Who is online

Users browsing this forum: No registered users and 0 guests