Altering data series and pipe them to the next plugin

Posted on
Tue Mar 05, 2019 1:47 pm
msageryd offline
Posts: 23
Joined: Jan 24, 2019

Altering data series and pipe them to the next plugin

Is there any way to calculate a dataseries of my own based on received z-wave data and use this series as input to another plugin? I'm sorry if this is a stupid question. I don't know how Indigo plugins works. I'm kind of hoping that they can work with data as streams which are pipeable between plugins.

More specifically, I need to calculate a difference between current and last value and divide it by the time delta and get hold of this data in Grafana. I'm using the Grafana Home Dashboard plugin.

Why do I need this?

I want to plot accurate power consumption charts (W), but:

1. The Aeotec reports accumulated energy (kWh) and momentary power (W). Unfortunately, the W readings are not averaged since last reading,
i.e they are essentially unusable for charts.

2. InfluxDB does not seem to have functions for making this calculation (surprisingly)

Code: Select all

Data reported from Aeotec HEM

| energyAccumTimeDelta | energyAccumTotal | energyCurrLevel |
| 0.50 hours           | 1 kWh            | unusable value  |
| 1.4 hour             | 4 kWh            | unusable value  |


Instead I want to feed the following to InfluxDB via the Grafana plugin:

| energyAccumTimeDelta | energyAccumTotal | averagePower          |
| 0.50 hours           | 1 kWh            |                       |
| 1.4 hour             | 4 kWh            | (4-1) / 1.4 = 2.14 kW |

Posted on
Tue Mar 05, 2019 4:48 pm
Dual offline
Posts: 259
Joined: Feb 05, 2019

Re: Altering data series and pipe them to the next plugin

msageryd wrote:
I need to calculate a difference between current and last value and divide it by the time delta

I want to plot accurate power consumption charts (W), but The Aeotec reports accumulated energy (kWh) and momentary power (W). Unfortunately, the W readings are not averaged since last reading,


If I am following you, a possible solution (screenshots) is shown below (consisting of 6 variables, 1 trigger with 5 actions including a python script as the 5th action):
Attachments
01.png
01.png (93.44 KiB) Viewed 1001 times
02.png
02.png (77.96 KiB) Viewed 1001 times
03.png
03.png (94.2 KiB) Viewed 1001 times
04.png
04.png (262.26 KiB) Viewed 1001 times

Posted on
Wed Mar 06, 2019 5:17 am
msageryd offline
Posts: 23
Joined: Jan 24, 2019

Re: Altering data series and pipe them to the next plugin

Thanks a bunch!
This seems to solve the problem, but it's way too much work imo. I have three Aeotec meters, so the variables and scripts would be quite messy.

Would it be possible to implement something like this with Indogos plugin structure?
https://www.home-assistant.io/component ... tatistics/

Posted on
Wed Mar 06, 2019 8:33 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Altering data series and pipe them to the next plugin

It is possible to interact with plugins in this way, and the Matplotlib plugin shows one way to do this. Using this structure:
Code: Select all
matplotlibPlugin = indigo.server.getPlugin("com.fogbert.indigoplugin.matplotlib")
payload = {'x_values': [1, 2, 3],
           'y_values': [2, 4, 7],
           'kwargs': {'linestyle': 'dashed',
                      'color': 'b',
                      'marker': 'd',
                      'markerfacecolor': 'r'},
           'path':'/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/images/controls/static/',
           'filename': 'chart_filename1.png'
           }
try:
    result = matplotlibPlugin.executeAction('refreshTheChartsAPI', deviceId=0, waitUntilDone=True, props=payload)
    if result is not None:
        indigo.server.log(result['message'])
except Exception as err:
    indigo.server.log(u"Exception occurred: {0}".format(err))

you can pipe data to the plugin and have it output charts on demand.

That said, use some caution. A plugin developer may not expect you to use their plugin in that way, and future changes to the plugin's code could break your script. With respect to the example above, the plugin method is designed specifically for that purpose and I plan to maintain backward compatibility of the plugin API as much as possible.

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

[My Plugins] - [My Forums]

Posted on
Thu Mar 07, 2019 3:14 am
msageryd offline
Posts: 23
Joined: Jan 24, 2019

Re: Altering data series and pipe them to the next plugin

Thanks Dave.
With this information at hand, I'll back down a bit from this project. I don't want to mess with things that could bite me in a year or two when a plugin stops working due to my tampering.

Instead I have increased the logging frequency so InfluxDB's last() and difference() can give me very near correct data.

Posted on
Thu Mar 07, 2019 6:38 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Altering data series and pipe them to the next plugin

If you're sending data to the plugin, it's unlikely that you'll break it, and this approach wouldn't change anything within the Grafana plugin itself.

I don't use the Grafana plugin, but you could also potentially use a feature of the Matplotlib plugin to save your data to a CSV file. Save your data values to Indigo variables and use the Matplotlib Plugin CSV Engine device to store the data over time. Then perhaps you'll be able to chart that with Grafana?

A great thing about Indigo is that there's almost always more than one way to get a job done.

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 14 guests