Looking for a special solution for total uptime and counting on/off switching

I am looking for a special way to count/measure and analyse binary and analog signals.
My current software is a TIG stack and MQTT on a raspberry pi 3.0 (Grafana v5.0.0, InfluxDB 1.8.3, Telegraf 1.16.1)
I did a lot of research, but at the moment I am a little bit lost :-/

For simplicity I would like start with some graphics.

I get two different types of signals from my home automation system:

Binary signals (on/off) from doors, various switches, valves, etc. (the first 6 signals in the graph above).
Analog signals such as the power/current consumption of e.g. an refridgerator (the last signal in the graph).

I would like to do for all signals:

  1. count the number of “on” events of each signal (analog/binary)

  2. count the number of “off” events of each signal (analog/binary)

  3. measure the over all “on” time of each signal (analog/binary) (Ton1+Ton2+Ton3+…)

  4. measure the over all “off” time of each signal (analog/binary) (Toff1+Toff2+Toff3+…)

I would like to show these values in “Singlestat” panels and also in some “Graph” panels too - but not in the “Discrete Panel” addon.

  1. after some maintenance work (e.g. defrosting the fridge or replace a water valve after 100.000 switching times) I would like to compare the on/off times of the refrigerator/water valve before and after defrosting/replacement to prove how successful the maintenance work was.

So I am thinking to reset the counting and the time measurement to zero, and start again.
The external reset could be a button in Grafana, or maybee a http event from “outside” ?

While writing it down, I realized that it is very difficult to explain my special case :wink:

When topics 1 to 4 have been solved, I need a “marker” to identify the exact time of the event when some maintenance was performed. This “marker” should be a “hard” one so I was thinking about resetting all counts to zero.
The best solution would be to automatically switch between the different maintenance events, but I have no idea how this could be possible …

  1. Perhaps it is better not to do a “reset”, but to use a parallel signal/value as a “marker” (e.g. a time stamp that only changes when the maintenance work is finished) so that I can navigate between the events.
    Could this “time stamp” be used to navigate in Grafana?

If some one can give me some advice how I can solve topics 1 to 5/6 I would be very happy.

Thank you in advance, Armin

1 Like

Hello @ArminPP,
I think I understand your problem but please let me know if I’m missing anything. I’m not sure about the best way to do this with Grafana, but I can help on the Influx side.

First I would run a task with a threshold that assigns the data to a “on” or “off” status (or potentially a deadman alert would work here? I don’t know if you have no data coming in during the off period or data=0). I believe the monitor states documentation will be useful to you.

I also hope these blogs will be useful to you:

Now to answer your specific questions:

  1. and 2. I would use monitor.stateChanges() within a task to count the number of “on” states.

3 and 4. I would use the stateDuration() to monitor the time of each signal.

  1. After defrosting you could perform another task to add a tag to the data to identify that work has been performed. For example set() might work.

  2. Alternatively you could just write a point to InfluxData to include these markers. This blog talks about the various ways to easily write one point (or a few points) to InfluxDB. TL;DR Tech Tips — How to Construct a Table with Flux | InfluxData