Hello openHAB Users,
a weather station provides really interesting input for a smarthome. I’m using a “indoor” weather station with the OH binding “tinkerforge”, which works great. Pressure, luminance and humidity (this value has to be handled carefully, it depends on the temperature) are shown in the UI and stored in a chart.
Now i added a “outdoor” weather station. The waterproof sensor lies outside the house and send its data via radio to the receiver (called Outdoor Weather bricklet). There are several more sensors available, like wind and rain sensors. This system is not yet implemented in the OH Binding.
1. Command: I can run a script in the shell, to read the values from the tinkerforge system (running on an remote raspberry):
user@openhab:~$ /home/user/tinkerforge/tinkerforge --host 192.168.178.137 --port 4223 call outdoor-weather-bricklet Es8 get-sensor-data 24
output
temperature=237
humidity=55
last-change=19
2. Command: You can parse the output for the temperature:
user@openhab:~$ /home/user/tinkerforge/tinkerforge --host 192.168.178.137 --port 4223 call outdoor-weather-bricklet Es8 get-sensor-data 24 --execute "echo 'scale=2; {temperature} / 10' | bc | xargs printf '%.1f\n'"
output:
23,7
(followed: Tinkerforge Formatting Output and Outdoor Weather Bricklet )
Now, i want to process these values with openHAB.
Used this document: OH Exec Binding
This thing causes a problem:
Thing exec:command:get_outdoorweather_temp [command="/home/user/tinkerforge/tinkerforge --host 192.168.178.137 --port 4223 call outdoor-weather-bricklet Es8 get-sensor-data 24 --execute "echo 'scale=2; {temperature} / 10' | bc | xargs printf '%.1f\n'"", interval=0, autorun=true]
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'weatherscriptexe.things' has errors, therefore ignoring it: [3,187]: missing ']' at 'echo'
[3,224]: no viable alternative at input 'bc'
[3,250]: missing EOF at '""'
The double quotes after the “–execute” argument are misinterpreted. OH wants the thing to be ended with square brackets. I tried, in OH and in the shell, to exchange the double qoutes with single qoutes, but that doesnt worked. So i cannot use this command to provide openhab a single number (here the temperature).
Next approach is to parse the output with regex within OH. Here the first command from above is used:
Thing exec:command:get_outdoorweather_raw [command="/home/user/tinkerforge/tinkerforge --host 192.168.178.137 --port 4223 call outdoor-weather-bricklet Es8 get-sensor-data 24", interval=0, autorun=true, transform="REGEX((.*?))"]
therefore a rule ist needed (from the OH Docs):
rule "Your Execution"
when
Item YourTrigger changed
then
get_outdoorweather_temp_out.postUpdate(get_outdoorweather_raw.state)
end
When the rule is triggered via the item “YourTrigger”, the logging shows:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Your Execution': The name 'get_outdoorweather_raw' cannot be resolved to an item or type; line 29, column 46, length 22
end
My goal is, to read the whole output from the the shell script and show it as a string. The next step would be, to alter the regex expression and convert the string to different number variables (temperature, humidity) to use them in a chart or rule.
The demo rule points in the right direction:
// If the returned string is just a number it can be parsed
// If not a regex or another transformation can be used
YourNumber.postUpdate(
(Integer::parseInt(yourcommand_out.state.toString) as Number )
)
but i’m stuck with both ways: neither i can execute the script, which gives back a number, nor i can parse the script which gives me back a string.
I would be really happy, if someone gives me a hint!
Certainly, extending the original tinkerforge binding with this new outdoor weather extension would be fine.
Have a good day!
Richard
Similar topics:
https://community.openhab.org/t/regex-transformation-please-help/26604
https://community.openhab.org/t/openhab2-exec-binding/27819
https://www.openhab.org/addons/transformations/regex/