Graph Switch State

Many of my switch devices have on / off as state (instead of 1 or 0). Is it possible for HABmin to graph these? (I’m using OH2)

I know you can chart them using InfluxDB and Grafana so I would guess that HABmin should be able to chart them, so long as the underlying database saves them as 1 and 0 which I’ve seen reports that rrd4j no longer does.

Thanks rlkoshak, excellent suggestion. I switched my MySQL dB to InfluxdB this weekend. I’m loving the Grafana charts!

@rlkoshak wrote: “I know you can chart them using InfluxDB and Grafana so I would guess that HABmin should be able to chart them, so long as the underlying database saves them as 1 and 0 which I’ve seen reports that rrd4j no longer does.”

I too am trying to show the state of on/off switch (Sonoff smart plug) in a Grafana chart, using an Influx db, but I’m struggling despite a lot of searching! The Sonoff sends its state via Mosquitto as ON or OFF, and although I’ve included a map file in my items file, I must have missed something because it seems the data is not being stored in Influxdb (or indeed displayed in OpenHAB2). The section I’m using in my items file is

Switch Heater_Outdoor_Garage_Loft “Garage Loft heater” (gInflux, gGar, heating) { mqtt=">[mqttbroker:cmnd/sonoff/1/POWER:command:ON:1],>[mqttbroker:cmnd/sonoff/1/POWER:command:OFF:0],<[mqttbroker:stat/sonoff/1/POWER:state:MAP(onoff.map)]", autoupdate=“false”}

and the map file (/etc/openhab2/transform/onoff.map) contains

0=OFF(CR)(LF)
1=ON

Two things I’m wondering about

  • is the (CR)(LF) in the map file wrong (by contrast, my items file only has (LF’s)
  • is the map file the wrong way round, should it perhaps be OFF=0 ON=1?
    Any help gratefully received!

The map file only applies to the Switch. If it successfully flipped the switch on and off when the appropriate MQTT message is received then everything is working. If not your map is wrong.

Once the Switch is behaving appropriately than you should be able to chart it.

In openHAB’s charts, one could chart OnOffType or OpenClosedType states in 1.8.3 (which map to 1 and 0 in the chart), but this PR would have to be merged in order to have the same ability in 2.x.

Thanks to @rlkoshak and @watou for your replies. I did some more on this and now have it working - thanks!
There was one more step required in addition to the above. As I mentioned in my first post, the Sonoff firmware (TASMOTA by Theo Arends) was by default sending a payload of ON or OFF via MQTT. When I thought about this, I realised it might be better to have it send 1 or 0 instead, which should give suitable values for Influxdb to store successfully, and be transformed via onoff.map for OpenHAB. After a bit of digging in the Sonoff firmware config I found an option to select exactly this, as well as a parameter to invert the values if required. So I changed it to output 0 for Off and 1 for On (confirmed using MQTTSpy). That solved the problem for me, there is now data going into Influxdb and I can use it in Grafana, and the switch still works correctly in OpenHAB2.
A result! Thank you. :smiley:

I haven’t tried the openHAB charts mentioned by @watou, instead I’ve “jumped” perhaps to using Grafana/Influxdb, but as time goes on I’ll give them a try (I may be best waiting for the PR to be merged).

1 Like

Hey Andrew - I have this exact problem - could you elaborate where you found the firmware config change?
Also, is the change something that I can make on the web interface, of am I going to have to reflash the firmware?

Thanks

Found it thanks - although in the end I just went with a simple rule to log state as 1 / 0 to a dummy item, rather than change the MQTT messages.

Plan is anyway to use the ON states as target temperature values when the switches are on - so I can map on the same axis as current temperature.