So webhooks are definitely the way to go so we don’t have to poll.
My current setup is to use the http binding, add a “thing” which has the command path to the script.
sh /home/openhabian/kegbot1.sh
The Output channel maps to the “volume remaining” item which is essentially the variable.
In the script is
#!bash
curl -sS http://192.168.1.22/api/taps/?api_key=xxxxxxx | \jq ‘.objects[0].current_keg.volume_ml_remain’
so the script is called by the http binding (it essentially is just used to poll stuff I think), the script hits the krgbot API and pulls back the volume remaining.
Similarly I pull back the keg name using a separate script.
#!bash
curl -sS http://192.168.1.22/api/taps/?api_key=xxxxxxx | \jq ‘.objects[0].current_keg.type.name’
I have the two scripts for each tap.
Now how we get openhab to receive the webhook I am unsure
Items are
//Takes the output from the “thing” - the thing executes the script bash file that runs the curl command with the jq filter
String tap1_vol_remaining {channel=“exec:command:kegbot_poll1:output”}
String tap2_vol_remaining {channel=“exec:command:kegbot_poll2:output”}
String tap3_vol_remaining {channel=“exec:command:kegbot_poll3:output”}
//String tap4_vol_remaining {channel=“exec:command:kegbot_poll4:output”}
//String tap5_vol_remaining {channel=“exec:command:kegbot_poll5:output”}
//String tap6_vol_remaining {channel=“exec:command:kegbot_poll6:output”}
Group gAllTapRemain
Group gAllTapName
//will be converted from string above to a number
Number tap1_vol_remaining_num “Tap1 [%d]” (gAllTapRemain)
Number tap2_vol_remaining_num “Tap2 [%d]” (gAllTapRemain)
Number tap3_vol_remaining_num “Tap3 [%d]” (gAllTapRemain)
//Names of kegs
String tap1_name “Tap1 [%s]” (gAllTapName) {channel=“exec:command:kegbot_name1:output”}
String tap2_name “Tap2 [%s]” (gAllTapName) {channel=“exec:command:kegbot_name2:output”}
String tap3_name “Tap3 [%s]” (gAllTapName) {channel=“exec:command:kegbot_name3:output”}\
then my rules are:
//converts string to number
rule “convert tap1 to number”
when
Item tap1_vol_remaining received update
then
tap1_vol_remaining_num.postUpdate(Double::parseDouble(tap1_vol_remaining.state.toString) / 1000)
end
//converts string to number
rule “convert tap2 to number”
when
Item tap2_vol_remaining received update
then
tap2_vol_remaining_num.postUpdate(Double::parseDouble(tap2_vol_remaining.state.toString) / 1000)
end
//converts string to number
rule “convert tap3 to number”
when
Item tap3_vol_remaining received update
then
tap3_vol_remaining_num.postUpdate(Double::parseDouble(tap3_vol_remaining.state.toString) / 1000)
end
rule “Tap pour”
when
Member of gAllTapRemain changed // one Tap was changed
then
if(previousState === null) return; // startup, so stop rule
var String strTap = triggeringItem.name.split(“_”).get(0) // get Index
var iTapName = gAllTapName.members.filter[i | i.name.contains(strTap)].head // get Name as Item
if ((previousState as Number) > (triggeringItem.state as Number)) { // if level has fallen
Garage_Speak.sendCommand('Enjoy '+ iTapName.state) // say the Name…
sendNotification(“[email protected]”,"Beer Poured - "+ iTapName.state)
}
end