Hello
I’m new to Openhab but i’ve found it intriguing how configurable it is and defiently like it
I’ve although ran into a problem i hope you guys can assist me with in respect to “Exec-bindings”
A bit about my project:
I’m running OH2 (ver 2.2.0) on my Synology 218+
I’ve installed OH2 through the via https://docs.openhab.org/installation/synology.html
– As this is a manual install via synology i do not get a “service” running, at least what i can track… but OH2 functions without problems.
– When i have to restart the OH2 it’s a bit of pain as i need to restart the entire NAS…
I’ve already got various widgets to work in HABPanel so it’s up and running…
My problem:
I want to take data from my own MySQL database (No MySQL persistent bindings is not an option, i want it from my external DB), in this case the simply the latest temperature
I’ve found out the best way to do this must be via exec bindings… i hope…
I’ve created a php script that works with no problems if I use it through the web browser of the Synology or via putty ssh. My return string from the php script is JSON and an example would be: [{“temperature”:“22.3”}]
– I do need to write php56 test.php (in putty) before it works though… using php test.php only, it will fail on mysqli… (which is kind of funny as if i write php -v i get the 5.6 version…)
Next step is that i’ve used exec binding via Things in the following way (My test.things):
– I’m pretty sure this is where my issue is, but i simply dont get how to test if this “thing call” works?
– It doesnt show up in PAPER UI -> Configuration -> Things (but perhaps it shouldn’t?)
– How do i determine if the path is correct?
– How do i determine if the “transform part” is correct?
– How do i determine if any value is coming from the command?
Afterwards the next step is to put in into items (test.items):
Number OutsideTemp1 "Temperature [%.2f °C]" {channel="exec:command:TempOutsideScript:output"}
Finally i added a template widget to the HABPanel which just shows the value for now, which returns “NULL”:
{{itemValue('OutsideTemp1')}}
The event.log only shows that:
Link ‘OutsideTemp1-exec:command:TempOutsideScript:output’ has been added.
The openhab.log shows (which means it is runnung…):
2018-02-18 17:43:29.570 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘test.things’
2018-02-18 17:54:16.961 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘test.items’
I hope you guys can help me, or tell me if i’m doing some basic stuff wrong as i’m new too this.
If you need further information please let me know.
Regarding 1) If i browse to my openhab installation (volume1/@appstore/openHAB) the path is correct… although:
sudo -u openhab php ./conf/scripts/TempOutside1Latest.php returns error in php file… (related to topic i wrote earlier)
sudo -u openhab php56 ./conf/scripts/TempOutside1Latest.php returns the [{“temperature”:“22.3”}]
Would you assume this to be a problem, my guess is that openhab only uses “php”?
If i remove the transformation, i should also be able to see the string value printed without any rule (when i change the item to a string) isn’t that correct? (I tried this, but doesnt work :))
You should see what the exection returns when you use the item as text in your sitemap. But i have made the experience that setting up a rule and trigger that with a swicht, as shown in the examples, is the best way to debug the execution of script etc. As the Text Item is also limited in how many character it displays.
If you need to execute it with php56 then just change the exec line.
Well i tried to make it really simple, simply having the php script returning as JSON “22.3” string with no data handling in the script at all…Which also runs fine from the terminal.
Regardless of the string returning exactly “22.3” or not i should still get something through the item and onto the sitemap/habpanel… but nothing…
Perhaps i’m failing on some other basic stuff, something i’m missing?
Do you need to do anything but have:
– X.things
– X.items
– X.sitemap
Do i need somehow to indicate Openhab to run those “X.things” files? (as far as i can read myself through they should be run automatically)…
I tried using your example with the CPU temperature from the RPI system temperature link you provided… here you don’t use a switch either to get the CPU temperature out… i’m pretty sure i’ve done more or less the same (except for exluding the persistant part)
I’ve tried to add the thing to overview.things, and added the Switch/String to overview.items, and the rule to overview.rules.
I’m presented with nothing (compared to “-” before) in the overview.sitemap, see code:
sitemap Overview label="Overview"
{
Frame {
Text item=OutsideTemp1
}
Frame {
Text item=OutsideTemp1clean
}
Frame {
Text item=php_run
}
Frame {
Text item=php_Out
}
Switch item=php_run label="PHP RUN" icon="light"
}
Additionally if i go all the way to the root in putty LoginName@UnitName:/ and write:
php56 -f volume1/@appstore/openHAB/conf/scripts/TempOutside1Latest.php
i still get the “28.2” value…
Could there be something with the LoginName@UnitName ?? (i mean i’m not using “Admin” but my created login to the Synology to connect to putty?)
It seems to me like the “Thing” stuff isn’t run, since there’s no info in any log file what so ever… (unless there are other important log files than in userdata/logs
I do get the following in event.log:
2018-02-19 20:16:54.430 [ome.event.ItemCommandEvent] - Item ‘php_run’ received command ON
2018-02-19 20:16:54.431 [vent.ItemStateChangedEvent] - php_run changed from OFF to ON
2018-02-19 20:16:54.962 [ome.event.ItemCommandEvent] - Item ‘php_run’ received command OFF
2018-02-19 20:16:54.963 [vent.ItemStateChangedEvent] - php_run changed from ON to OFF
Hey Josar
Yep, but it appears i’m a total rookie in the Xbase / Xtend language…
You told me to not use transformation on “Things”, which means i must do it on rules.
I was thinking something like:
rule "OutsideTemperatureConversion"
when
Item OutsideTemp1 received update
// My item that is updated from Things returning [{"temperature":"22.3"}]
then
OutsideTemp1Numb.postUpdate(12133) // Simply a test to update into a number, which works fine
OutsideTemp3.postUpdate(transform("REGEX","\btemperature":"\K\S+[[:digit:]]",OutsideTemp1.state)
// my idea, but doesnt work... it should return 22.3.. and tried to print it both as a number and string item, neither works..
// I tested the command via https://regex101.com/ on the string [{"temperature":"22.3"}]
// I tried with jsonpath conversion also, didnt seem to do the trick either..
end
I’m obviously not understanding the language, do you have any insight?
At least one error "\btemperature":"\K\S+[[:digit:]]". The inner " has to be escaped as you embedd them in a string. "\btemperature\":\"\K\S+[[:digit:]]".
if you want to do it in the rule. Explanation for the regex see below.
rule "OutsideTemperatureConversion"
when
Item OutsideTemp1 received update
then
OutsideTemp3.postUpdate(transform("JSONPATH","$..temperature",OutsideTemp1.state)
OutsideTemp3.postUpdate(transform("REGEX","s/.+:.(.{4}).+/$1/g",OutsideTemp1.state)
end
or with regex and the unchanged string, but should also work with the changed string. .+:.(.{4}).+ This is the regex : " All character, one :, one charater , a group of 4 character which will replace $1, all character left.
or this one .*:.(.*).}] which you can decipher on https://regex101.com