Today, I’ve got 4 knx sensors (1-2-3 & 4) to measure the level of my well. I would like to put the these values in a text file. And at the end, I’m creating a rrdtool with this through cacti.
Today, this was done with a bash script that read the values out the linuxmce database. But of course, I’m open for all suggestions… So what’s the best way to write this to a file with openhab?
Did I understand it right, that the 4 sensors are in fact ON/OFF, so:
Water level | Sensor 1 | Sensor 2 | Sensor 3 | Sensor 4
0 - 0.9 | OFF | OFF | OFF | OFF
1 - 1.9 | ON | OFF | OFF | OFF
2 - 2.9 | ON | ON | OFF | OFF
3 - 3.9 | ON | ON | ON | OFF
4 & above | ON | ON | ON | ON
?
Then I would suggest to build a bunch of Items:
Group well
Switch well_1 "Level 1 is [%s]" (well) {knx="GA1/1/1"}
Switch well_2 "Level 2 is [%s]" (well) {knx="GA1/1/2"}
Switch well_3 "Level 3 is [%s]" (well) {knx="GA1/1/3"}
Switch well_4 "Level 4 is [%s]" (well) {knx="GA1/1/4"}
Number well_level "Well level is [%d]" //proxy item, no Binding, no group!
a simple rule:
rule "well level"
when
Item well received update
then
if (well_4.state == ON) well_level.postpdate(4)
else if (well_3.state == ON) well_level.postpdate(3)
else if (well_2.state == ON) well_level.postpdate(2)
else if (well_1.state == ON) well_level.postpdate(1)
else well_level.postpdate(0)
end
Do persistence to well_level (strategy: everyMinute) with rrd4j.
What’s missing is Average and Maximum, but you can calculate this through another rule, maybe combined with a setpoint item to choose the period, and show the values through openHAB items.
as the group, no rule nor proxy item needed at all, the well.state will show the level so persistence is done to the group item itself (use well in persistence file, not well*)
And in the sitemap, I’ve put following, just for testing now:
Text item=WOWaterput icon=“cistern”
But I’m not getting any data. It stays on (0).
After checking the log files, it seems that the sensors (contact_WO_Waterput_*) aren’t triggered? Is that only been filled in if the sensor changes? If so, is there a way to force this status update?
ps in your example, you write knx="GA1/… Does the GA part do anything special?
hmmm, think I’ll need to check the knxbus a bit more closely, as you mention.
In the openhab.log, I’m getting follwoing entry after adding the ‘<’:
2016-05-20 06:09:35.156 [WARN ] [.KNXBindingDatapointReaderTask] - Autorefresh: Cannot read value for item ‘contact_WO_Waterput_2’ from KNX bus: timeout waiting for group read response: timeout
The knx inputs are a ABB I/O device for bus system 4 In/ 4 Out US/U 4.2.
I’ll see if I can find something in ETS that could explain this.
ps I’ve also added the < before a working GA, and it’s giving me the same error in the log.
You have to set the R-Flag in the ABB I/O device for each GA you want to read from the knx bus. The R-Flag should be set in for exactly one communication object per Group Address, usually the status CO of an actuator, but I think there is no such device for this GA :). Of course the C-Flag has to be set, just as the T-Flag.
Flag
C (Communicate): The device will communicate with the bus.
R (Read) : The communication object is readable (i.e. it will answer a read request)
W (Write) : The communication object is writable.
T (Transmit) : The communication object will send changes in value
U (Update) : The communication object update it's value if other bus subscribers will answer a read request.
Cool! I can now read nicely the status through openhab after updating the R flag.
Next step (hopefully tomorrow),I can adding the info to a graph. I’ll let you know how this is going…
rule “Waterput Niveau Voor grafieken”
when
Time cron “0 0/5 * * * ?”
then
if (contact_WO_Waterput_4.state == ON) {
executeCommandLine(“/etc/openhab/configurations/scripts/waterput.sh 4”)
} else if (contact_WO_Waterput_3.state == ON) {
executeCommandLine(“/etc/openhab/configurations/scripts/waterput.sh 3”)
} else if (contact_WO_Waterput_2.state == ON) {
executeCommandLine(“/etc/openhab/configurations/scripts/waterput.sh 2”)
} else if (contact_WO_Waterput_1.state == ON) {
executeCommandLine(“/etc/openhab/configurations/scripts/waterput.sh 1”)
} else
executeCommandLine(“/etc/openhab/configurations/scripts/waterput.sh 0”)
end
And /etc/openhab/configurations/scripts/waterput.sh is a little script to put the status in a text file with the date. And at the end, this file is being send to the monitoringserver (cacti) to be converted in a rrd file.