Next problem: all my Fibaro FGWPE/F-102 wall plugs appear as unrecognised.
Also the Fibaro flood sensors.
The Aeotec sensors,TKB wall sockets and the SIR timer are working.
I decided to try making a binding for the Awair air quality sensor. I downloaded the addons package and found the Foobot binding, which is really similar to the Awair in every respect. I modified it for the Awair and now I need to test it. Iāve spent hours fiddling around with Eclipse and setting up the dependencies, but to no avail so far. I tried following a couple of how-tos on the OpenHab site, but also without success. Iāll carry on next week.
I eventually worked out how to set up the Eclipse environment and eliminated all the reported errors. After more than a month Iāve come back to it with the objective of generating a .jar for testing. After a couple of attempts I managed to get the jar generated by executing this command:
mvn clean install -DskipChecks
on the addon directory (org.openhab.binding.awair). Before doing that you need to clean up the code formatting with:
mvn spotless:apply
Now I have some errors to deal with from the automatic tests.
Fixed the test errors. Now Iām ready to test the addon on my system.
Ahh, not quite. I got the 3.00 addon fixed, but not the 2.5x addon, and itās still giving me problems with dependencies. Iāve just noticed that itās asking for JRE 1.8, which I donāt have.
I got the 2.5.x version built. First, you donāt need the core from github (for which only the 3.0.0 branch is needed). But that wasnāt my problem. As explained here:
https://community.openhab.org/t/eclipse-setup-for-developing-2-5-x-addon
the imports change in 3.0.0. I had the imports right for 3.0.0, not for 2.5.x. I changed:
org.openhab.core
to
org.eclipse.smarthome.core
and also had to change the unit test imports and add a few more imports that seem to be needed in 2.5.x (I copied what I found in the 2.5.x version of the foobot binding).
Also, at the end of the Maven build I got a ton of errors starting with this:
Feature resolution failed for [openhab-binding-awair/2.5.11.SNAPSHOT]
[ERROR] Message: Unable to resolve root: missing requirement [root] osgi.identity;
Hunting around on the forum, I found this post:
And changed the following in feature.xml in my binding:
<bundle start-level="80">
to
<bundle dependency="true">
I have absolutely no idea what it does, but it got rid of the errors.
I can now test the binding on my OH system.
I tested the Awair binding and got to the point where it appears in Bindings in Paper UIā¦ and thatās it. Oh well, itās a start. No entries appear in the main logs, although I tried to set up logging for the binding as described here on the forums. To be investigated.
I decided to press ahead with creating the building blocks of my rules. I said I was going to go down the Jython route, but the flesh is weak, so Iām going to use Javascript.
I read here that you couldnāt put non-rule utility function .js files in the rules folder, but I found the opposite to be the case. If I put them in another parallel folder, they are found by the rules engine, but attempts to call the functions seem to fail. If I put them in the āpersonalā folder, they work. I include them in the same way as the rules.js file:
load(Java.type("java.lang.System").getenv("OPENHAB_CONF")+'/automation/jsr223/javascript/personal/WeekdaysAndHolidays.js');
One thing Iāve noticed is that changes are only applied on restart.
Lots of progress today. First, I realised I needed to add the Awair bridge manually (duh). As soon as I did that, I was able to (try) to add a device and saw entries in the log. The device didnāt add because of a stupid typo in the binding. Iāll try the corrected version now.
I also saw a post that cleared up the confusion about the WeatherUnderground Personal Weather Station binding. If you have a PWS, the WeatherUnderground binding does not work, you need the Weather Forecast Company one.
A bit more progress. The Awair binding shows the right things and items, and it connects to the account, but discovery doesnāt work, and something goes wrong with reading the values when a device is added manually.
Awair binding now fully working. I need to get the 3.0 version compiling and work out how to get it included in future builds.
I spoke a bit too soon. I canāt get the item units to appear in PaperUI.
Iāve migrated quite a few rules from the Zipabox.
Trying to work out how to access the last position that Somfy RTS blinds and awnings were set to.
Added an items file to create groups and items for last update time stamps for various sensors and stuff, as described here:
The groups and items were no problem (I hadnāt noticed that items have a āparent groupsā configuration". The tricky bit was working out how to implement the rule in Javascript. After a lot of fiddling I came up with a helper function to extract the name of the item updated from the āinputā parameter:
// Adapted from https://gitlab.com/RNTs_3/openhab-jsr223-javascript-helper/tree/master
function GetTriggerItemForEvent(input)
{
var ev = input.get("event")+"";
// Splits into: 'gRecordLastUpdate,changed,from,7.96612745098039237,to,7.95362745098039237,through,BalconyAeotec_SensorTemperature'
var evArr = ev.split("'").join("").split("Item ").join("").split(" ");
return evArr[7];
}
It seems that evArr[0] contains the group name, not the item name, when youāre capturing changes to all members of a group.
The rule looks like this, in case it helps somebody. I stuck three different triggers in there because I wasnāt sure which I needed. The last bit of the puzzle was working out that the date sent to sendCommand needed to be in ISO format (.toISOString).
JSRule
(
{
name: "Rule_LastUpdate",
description: "Store last update stamps for all items that require them",
triggers:
[
UpdatedEventTrigger("gRecordLastUpdate"), // Any Member of gRecordLastUpdate received update, even if the value didn't change
ChangedEventTrigger("gRecordLastUpdate"),
ItemStateChangeTrigger("gRecordLastUpdate")
],
execute: function( module, input)
{
// LastUpdate item has same name as item update, plus _LastUpdate
var itemLastUpdate; // Item containing last update date
// Get current date
var dateNow = new Date();
var sTriggerItemName = GetTriggerItemForEvent(input);
// LastUpdate item has same name as item update, plus _LastUpdate
itemLastUpdate = getItem(sTriggerItemName + "_LastUpdate");
sendCommand(itemLastUpdate, dateNow.toISOString());
}
}
);
After learning that I could access all items via the cloud through the REST API, I set up a myopenhab.org account, installed the REST API docs (in PaperUI: Add-ons -> User interfaces -> REST documentation) and looked up the methods for reading and setting an item state (look under https://home.myopenhab.org/doc/index.html).
I stumbled a bit when I decided to test the calls in the Advanced REST client tool. Iād read that the URL should take the form:
https://<myopenhab email>:<myopenhab password>@myopenhab.org:443/rest/items/<item name>/state
with the @ symbol of the email encoded as %40. I did this, but always got āunauthorizedā back. After beating my head against the wall for an hour, I realised that there is a specific section for inputting the basic authorisation user name and password . In the app I use on my phone to transmit certain information back to the controller (Llama Automate, sort of like Tasker), the HTTP Request blocks work in exactly the same way. So Iām now updating my first item over the cloud.
Next stop: persistence.
Iāve built a large part of my rules but thereās still quite a long way to go. Iām having trouble with exposed items at the moment. Despite apparently exposing them in PaperUI, the values seem hardly ever to arrive, or only very erratically. The UI for selecting items to expose is horrible, so Iām going to look at using the config file instead. At least then it will be clear whatās being exposed.
you dont need to have rule for it, it can be easily done by profile, for example Iām using this approach
Number:Temperature Water_Temperature "Water [%.1fĀ°]" <temperature> (gStore10, gGarden, gWeather, Graph_Water, Graph_Temperatures, Graph_InOutWater, gMinMaxDaily, gMinMaxAlltime, gMinMaxLastYear, Graph_Weather) ["Measurement","Temperature"] { channel = "mqtt:topic:garden_control:water" }
DateTime Water_Temperature_LastUpdate "Last change [%1$tR]" <time> { channel="mqtt:topic:garden_control:water"[profile="timestamp-update"] }
How does that work? Iām not familiar with profiles. How are the two items linked? (Also: is this an OH3 feature?)
Does this work when a value is updated but not changed?
whenever main item receives and update, this item is updated on timestamp as well.
They are linked by the channel, in this example via MQTT
mainitem -> { channel="mqtt:topic:garden_control:water" }
timestamp -> { channel="mqtt:topic:garden_control:water"[profile="timestamp-update"] }