New Plugin: GhostXML

Posted on
Mon Apr 18, 2016 9:13 pm
geoffsharris offline
Posts: 45
Joined: Nov 26, 2012

Re: New Plugin: GhostXML

Awesome plug in.

Just wondering if there is an elegant way to do the following:

Right now I have a personal weather station running on a local webserver. It outputs a simple xml file with time, temperature, humidity, etc. and it is currently parsed to indigo variables using a python script.

I can then use those variables to test against certain conditions to run a greenhouse automation program.

GhostXML is potentially a brilliant solution for my needs, but I am having difficulty setting up the device parameters in a trigger. I can set the variable, but it appears to be a string rather than a number and I therefore can't do a within a range comparison or higher of lower comparisons. As a work around I tried to figure out if I could set up a trigger to set all of the variables to values of the xml device, but couldn't figure out how to accomplish this either. Any thoughts?

Thank you!

-Geoff

Posted on
Tue Apr 19, 2016 5:51 am
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

Thanks!

The original thought was that since we don't know what each value is when we parse the data, the safe thing would be to convert everything to a string and then let the user sort out the details later. I definitely see the value in what you're suggesting, but need to think it through a bit more. We can evaluate every value and then say if it doesn't float, it must be a string, but I'm not sure what the load would be on cycle time. Also, we would need to set the proper state value type--float, int, string, etc. I think booleans would be even trickier (and maybe impossible.) There are possibilities here, but I need to do some cipherin' to think about the consequences.

Dave
(In all actuality, if it doesn't float, it must be a witch.)

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

[My Plugins] - [My Forums]

Posted on
Fri Apr 29, 2016 6:55 am
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

I wanted to post back so that you didn't think I forgot about this. I've been tied up with another project, but I may have stumbled across a possible solution to this problem. The trick is that we're constructing device states on the fly and need to establish what type of state it is when constructing it. The simple solution (e.g., easiest) was to just make everything a string. But the following method will at least establish whether a particular node *might* be an int or a float:

Code: Select all
from ast import literal_eval
def parses_to_integer(s):
    try:
        val = literal_eval(s)
        return isinstance(val, int) or (isinstance(val, float) and val.is_integer())
    except:
        return 'String'
   
print parses_to_integer('1')
print parses_to_integer('1.0')
print parses_to_integer('1.1')
print parses_to_integer('Foo')

>>> True
>>> True
>>> False
>>> String

The only downside that I see is that this will coerce '1.0' to an int when it is actually a float. This would cause a problem where users always expect a float value for a particular node.

Any thoughts?

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

[My Plugins] - [My Forums]

Posted on
Mon May 02, 2016 11:46 am
geoffsharris offline
Posts: 45
Joined: Nov 26, 2012

Re: New Plugin: GhostXML

Seems like it could work. I suppose only issue would be if someone was trying to evaluate a sting of "1" or "1.1" and had it converted to an int or float. Certainly wouldn't be a problem that I would run into.

-Geoff

Posted on
Mon May 02, 2016 4:03 pm
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

geoffsharris wrote:
Seems like it could work. I suppose only issue would be if someone was trying to evaluate a sting of "1" or "1.1" and had it converted to an int or float. Certainly wouldn't be a problem that I would run into.

-Geoff

Another great point (which I hadn't even considered.) I'm even more at a loss in how to do this without introducing danger. It would be great if the node type was exposed as a node attribute, but I don't see how we can count on that.

Dave

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

[My Plugins] - [My Forums]

Posted on
Tue May 03, 2016 4:48 pm
johnpolasek offline
Posts: 911
Joined: Aug 05, 2011
Location: Aggieland, Texas

Re: New Plugin: GhostXML

Actually, it looks like the "Insert Variable State into Variable" action already deals with that, at least for ints. If you create and initialize a variable to the type you want, inserting the state from Ghost coerces it correctly if possible... For example, I have a trigger "Dryer Power" which triggers on "has any change" to Channels_Channel_10_Real Power in the Sitesage device and inserts the state into a variable "DryerPower" which I initialized with a 0 when I created it. And I have a pair of triggers watching for any change on that variable, one of which turns On an appliance link tied to a plasma ball if the value is greater than 100, and another which turns off the appliance link whenever the value is less than 25. I haven't experimented with trying to send a string to a variable initialized with a number or even trying to send an int to a variable initialized with 0.0, but superficially it looks like Matt and Jay have already taken care of at least the legitimate cases if you're willing to work through a variable intermediate.

Posted on
Tue May 03, 2016 6:02 pm
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

johnpolasek wrote:
Actually, it looks like the "Insert Variable State into Variable" action already deals with that, at least for ints. If you create and initialize a variable to the type you want, inserting the state from Ghost coerces it correctly if possible... For example, I have a trigger "Dryer Power" which triggers on "has any change" to Channels_Channel_10_Real Power in the Sitesage device and inserts the state into a variable "DryerPower" which I initialized with a 0 when I created it. And I have a pair of triggers watching for any change on that variable, one of which turns On an appliance link tied to a plasma ball if the value is greater than 100, and another which turns off the appliance link whenever the value is less than 25. I haven't experimented with trying to send a string to a variable initialized with a number or even trying to send an int to a variable initialized with 0.0, but superficially it looks like Matt and Jay have already taken care of at least the legitimate cases if you're willing to work through a variable intermediate.

That's a good workaround and keeps the plugin from running the risk of potentially endangering values. While it's not optimal, it does seem to work well.

Thanks for pointing that out.
Dave

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

[My Plugins] - [My Forums]

Posted on
Thu May 05, 2016 2:26 am
Coolcaper offline
Posts: 299
Joined: Aug 30, 2013
Location: Australia

Re: New Plugin: GhostXML

Thanks for the plugin Dave! Seems to work with my wifi air conditioner! I can read all the settings so far. Next step would be to figure out how to make changes to the actual settings on the aircon.

Just an FYI for new users, it seems the data is not read from the address provided in the devices straight away, so just give it a bit of time till the 'Enabled' disappears from the 'State' column. This was what threw me when I tried the plugin the first time and nothing happened. Tried it again today and it has rendered one of my afternoon long struggle with an applescript useless! But its a good thing! :D

Posted on
Thu May 05, 2016 3:57 am
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

Coolcaper wrote:
Thanks for the plugin Dave! Seems to work with my wifi air conditioner! I can read all the settings so far. Next step would be to figure out how to make changes to the actual settings on the aircon.

Just an FYI for new users, it seems the data is not read from the address provided in the devices straight away, so just give it a bit of time till the 'Enabled' disappears from the 'State' column. This was what threw me when I tried the plugin the first time and nothing happened. Tried it again today and it has rendered one of my afternoon long struggle with an applescript useless! But its a good thing! :D

Glad to hear that it's working for you. Sorry about the confusion on the "enabled" thing--at some point I need to knuckle under and come up with a solid approach to refresh the devices after the config dialog is closed. It's on the list as they say. :D

The "work around" is to reload the plugin if you don't want to wait for the next refresh cycle

Enjoy!
Dave

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

[My Plugins] - [My Forums]

Posted on
Thu May 05, 2016 2:48 pm
Asconasny offline
Posts: 161
Joined: Jan 16, 2015

Re: New Plugin: GhostXML

Hi.

Just testing the plugin
I get this error:
Error getting source data: 'ascii' codec can't decode byte 0xc3 in position 295: ordinal not in range(128). Skipping until next scheduled poll.

The site I'm getting the XML from is this:
https://www.yr.no/sted/Norge/Rogaland/Karmøy/Vedavågen_kirke/varsel.xml

Seems like the same issue Håvard got earlier on. Any suggestions?

Regards
Asconasny

Posted on
Thu May 05, 2016 2:57 pm
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

Hi Asconasny - did the traceback give you a line number associated with the error?


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
Thu May 05, 2016 3:16 pm
Asconasny offline
Posts: 161
Joined: Jan 16, 2015

Re: New Plugin: GhostXML

Set the debug on high.
then i do a refresh and i get this in log file.:

GhostXML Debug refreshData() method called.
GhostXML Debug Updating data...
GhostXML Debug Found configured device: new device 3
GhostXML Debug new device 3 is enabled.
GhostXML Debug getTheData() method called.
GhostXML Error new device 3 - Error getting source data: 'ascii' codec can't decode byte 0xc3 in position 295: ordinal not in range(128). Skipping until next scheduled poll.
GhostXML Debug Device is offline. No data to return. Returning dummy dict.
GhostXML Debug Source file type: XML
GhostXML Debug stripNamespace() method called.
GhostXML Debug <?xml version="1.0" encoding="UTF-8"?><Emptydict><Response>No data to return.</Response></Emptydict>
GhostXML Debug Device needs updating set to: True
GhostXML Debug getDeviceStateList() method called.
GhostXML Debug Pulling down existing state list.
GhostXML Debug Writing dynamic states to device.
GhostXML Debug Device needs updating set to: False
GhostXML Debug parseStateValues() method called.
GhostXML Debug Writing device states:
GhostXML Debug Response = No data to return.
GhostXML Debug new device 3 updated.

Regards
Asconasny

Posted on
Thu May 05, 2016 3:33 pm
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

Thanks, that helps. I'll have a look.


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
Thu May 05, 2016 3:52 pm
Asconasny offline
Posts: 161
Joined: Jan 16, 2015

Re: New Plugin: GhostXML

Great! thanks :)


Asconasny

Posted on
Thu May 05, 2016 7:47 pm
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: New Plugin: GhostXML

Asconasny wrote:
Great! thanks :)


Asconasny


Asconasny - I believe that the error is being caused by the processing of the response from the sending server (not the returned XML itself.)

I'm about to send you a PM with a link to a (hopefully) workable version of the plugin to test.

Dave

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

[My Plugins] - [My Forums]

Page 4 of 20 1, 2, 3, 4, 5, 6, 7 ... 20

Who is online

Users browsing this forum: No registered users and 1 guest