Battery Charting Script

Posted on
Fri Apr 15, 2016 7:00 pm
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Battery Charting Script

I thought that might be the case. You'll need to also use the code in post #1 on this thread which includes changes to specifically address the error you were seeing. Sorry if that wasn't clear in my earlier post--I was rushing to get you something before I jumped on a plane.

If you have any questions, please do let me know!
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 16, 2016 12:30 pm
stuartcolman offline
Posts: 81
Joined: Nov 01, 2015
Location: Essex, United Kingdom

Re: Battery Charting Script

Dave,

Thanks for the update, however I am the bearer of bad news. I updated the script as mentioned and get the following error:

Code: Select all
Script Error                    embedded script: unsupported operand type(s) for +: 'int' and 'str'
  Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 117, at top level
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/pyplot.py", line 2107, in barh
       ret = ax.barh(bottom, width, height, left, **kwargs)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 4902, in barh
       orientation='horizontal', **kwargs)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 4784, in bar
       self.add_patch(r)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 1489, in add_patch
       self._update_patch_limits(p)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 1507, in _update_patch_limits
       xys = patch.get_patch_transform().transform(vertices)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/patches.py", line 547, in get_patch_transform
       self._update_patch_transform()
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/patches.py", line 543, in _update_patch_transform
       bbox = transforms.Bbox.from_bounds(x, y, width, height)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/transforms.py", line 745, in from_bounds
       return Bbox.from_extents(x0, y0, x0 + width, y0 + height)
TypeError: unsupported operand type(s) for +: 'int' and 'str'


I had a brief look, but it started to get a bit over my head.

Thanks

Stuart

Posted on
Sat Apr 16, 2016 3:35 pm
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Battery Charting Script

Hi Stuart - Please PM me the entire code block you're running. Your line 117 is not the same as mine and I don't know which part of code is barfing.

Thanks,
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 16, 2016 3:40 pm
stuartcolman offline
Posts: 81
Joined: Nov 01, 2015
Location: Essex, United Kingdom

Re: Battery Charting Script

PM'd

Posted on
Sat Apr 16, 2016 4:55 pm
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Battery Charting Script

I have updated the master script to address the 'str + int' error. See post #1 in this thread.

Dave

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

[My Plugins] - [My Forums]

Posted on
Wed May 04, 2016 8:55 am
Different Computers offline
User avatar
Posts: 2531
Joined: Jan 02, 2016
Location: East Coast

Re: Battery Charting Script

Looking at the code, I see the background is specified as a RGB value.

Is there a way to specify a transparent background?

I found
Code: Select all
plotly_fig = tls.mpl_to_plotly( mpl_fig )
plotly_fig["layout"].update({
                             "plot_bgcolor":"rgba(0, 0, 0, 0)",
                             "paper_bgcolor":"rgba(0,0,0,0)"
                             })
at https://plot.ly/matplotlib/backgrounds/ but that code doesn't look like it would just drop in to replace what's in the script.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed May 04, 2016 10:13 am
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Battery Charting Script

Different Computers wrote:
Looking at the code, I see the background is specified as a RGB value.

Is there a way to specify a transparent background?


Try changing the plot settings kwargs to this:
Code: Select all
k_plot_fig = {'bbox_extra_artists': None,
              'bbox_inches': 'tight',
              'dpi': 100,
              'format': None,
              'frameon': None,
              'orientation': None,
              'pad_inches': 0.1,
              'papertype': None,
              'transparent': True,
              }

This deletes the 'facecolor' and 'edgecolor' arguments. It should work.
Dave

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

[My Plugins] - [My Forums]

Posted on
Wed May 04, 2016 8:58 pm
ryanbuckner offline
Posts: 1072
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Battery Charting Script

need a little assistance here

Tested the imports and they work.
1) Copied your code into pico and output to battery.py file.
2) Created schedule in Indigo to execute battery.py and click on Execute Action Now.
3) Event log has schedule executing but no image in static dir and no errors

Thoughts?

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

Re: Battery Charting Script

ryanbuckner wrote:
need a little assistance here

Tested the imports and they work.
1) Copied your code into pico and output to battery.py file.
2) Created schedule in Indigo to execute battery.py and click on Execute Action Now.
3) Event log has schedule executing but no image in static dir and no errors

Thoughts?

Copy the code from post #1 in this thread and paste it into an Indigo scripting shell (you may have to hit return to get the last line to execute) and let me know if that works. This should also present you with any User Warnings that may be suppressed when the script is run as a linked script.

Dave

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

[My Plugins] - [My Forums]

Posted on
Fri May 06, 2016 6:49 am
Different Computers offline
User avatar
Posts: 2531
Joined: Jan 02, 2016
Location: East Coast

Re: Battery Charting Script

I was a little nervous about replacing the code, but it worked perfectly the first time. Thanks Dave!

I stared at the rest of the code for about 10 minutes and could not figure out how to get rid of the thin black line that frames the graph. What code creates that?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Fri May 06, 2016 9:13 am
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Battery Charting Script

Good deal. Glad that worked.

Can you please post a screen shot of what you're looking at? It will help me figure out what line you're seeing.

Dave

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

[My Plugins] - [My Forums]

Posted on
Fri May 06, 2016 10:58 am
stuartcolman offline
Posts: 81
Joined: Nov 01, 2015
Location: Essex, United Kingdom

Re: Battery Charting Script

Some of my devices which have the battery at zero are still showing. Is there a way to filter certain devices out?

Posted on
Fri May 06, 2016 11:44 am
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Battery Charting Script

stuartcolman wrote:
Some of my devices which have the battery at zero are still showing. Is there a way to filter certain devices out?

There sure is, but I wouldn't want to make it a part of the "official" script because I think a lot of users would want battery devices with 0 to show up. Here is one way. The script creates a list of device names (technically it's called a dictionary) that looks like this:
Code: Select all
device_dict = {"Device Name 1": 100, "Device Name 2": 75, "Device Name 3": 0}

Just above the line in the script that looks like this:
Code: Select all
# Parse the battery device dict into X and Y values

You'll want to add this:
Code: Select all
device_dict.pop("Name of Device You Want to Remove")
device_dict.pop("Name of Another Device You Want to Remove")

And repeat for each device you want to hide. This is completely inelegant because you'll have to go back and add new devices later when you add them to your system--and if you change a device's name the script will break, but it should work for you now right out of the gate.
Dave

p.s. I'll add a TODO to change the script to work with device IDs instead of names to fix the second problem.

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

[My Plugins] - [My Forums]

Posted on
Fri May 06, 2016 1:22 pm
Different Computers offline
User avatar
Posts: 2531
Joined: Jan 02, 2016
Location: East Coast

Re: Battery Charting Script

Here's a screenshot. I'm talking about the thin black line that surrounds the graph.
Attachments
Screen Shot 2016-05-06 at 3.20.31 PM.png
Screen Shot 2016-05-06 at 3.20.31 PM.png (180.96 KiB) Viewed 12581 times

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Fri May 06, 2016 1:39 pm
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Battery Charting Script

Different Computers wrote:
Here's a screenshot. I'm talking about the thin black line that surrounds the graph.

Try adding this:

plt.axis("off")

Before the "savefig" command.

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

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 1 guest

cron