I have a door sensor that retunes a 1 when the door is open and 0 when
closed stored in influxdb.
How often are you sampling the value?
This is the query in Grafana:
SELECT mode("value") FROM "bedroom" WHERE $timeFilter GROUP BY time(1s)
fill(previous) ```
This works ok if the value has changed during the set time period.
Ah, so do you actually mean “a sensor that returns a 1 when the door gets
opened, and a 0 when it gets closed”, in other words it only reports changes,
no the current state?
i.e. if the time period window is set to say 8 hours and the door is
opened, a value of 1 is displayed with a line showing the time the door is
open. after 4 hours if I change the time window to 3 hours the value is
showing anymore as open or closed.
Well, if the door has not been opened or closed during the time window, I
wouldn’t expect the graph to show any activity…?
Hope this makes sense, can anyone help with this please.
I guess it means you are actually interested in the continuous state of the
door (is it open or is it closed), and not so interested in the state changes
(has it just been opened or has it just been closed)?
The best way to do this would be to take continuous readings of the door’s
state (I suppose once per minutes would be accurate enough?), and then you
have the ideal thing for Grafana - time-series data which can be plotted over
whatever timescales you like.
If you cannot do this sort of pre-processing in whatever system is feeding
your sensor data into influxdb, then I suspect a Continuous Query might be able
to convert the state changes into continuous time-series data for you -
however I’m no expert on that, so maybe someone else can suggest if this would
work or how to do it.
You might also benefit from asking about this on the InfluxDB list, because it’s
more of a question about the data you’re putting into your data store than it
is about what Grafana does with it afterwards.
Grafana can’t show you the state of the door in the past hour if it hasn’t
been opened or closed for 2 hours - there just isn’t any information for
Grafana to work on.
Antony.