I’d like to use slack as a communication hub between openHAB and my family.
So I set up a slack channel and followed the instructions here: https://github.com/openhab/openhab/wiki/Slack-Integration and here https://gist.github.com/sumnerboy12 from @ben_jones12
So far i got the communication between slack and the python library up and running, the sample “repeat”-Plugin works fine. So I pasted the slackhab.py
in my plugins-folder. What I did come across: the “repeat.py
” example, python uses a class, which is referenced in rtmbot.conf
- the slackhab.py
isn’t, it’s just plain in the plugins.folder.
I’m using openHABian and OH2, if this has some Impact also.
rtmbot.conf
# Add the following to rtmbot.conf
DEBUG: True # make this False in production
SLACK_TOKEN: "xoxb-xxxx"
ACTIVE_PLUGINS:
# - plugins.repeat.RepeatPlugin
# - plugins.slackhab.openHABPlugin
rtmbot.log
2016-12-09 12:13:12,287 Initialized in: /usr/local/bin
2016-12-09 12:13:12,314 Starting new HTTPS connection (1): slack.com
2016-12-09 12:13:12,749 "POST /api/rtm.start HTTP/1.1" 200 4534
2016-12-09 12:13:13,401 Loading plugins
2016-12-09 12:13:13,405 No plugins specified in conf file
2016-12-09 12:13:13,407 got process_hello
2016-12-09 12:13:13,510 got process_presence_change
2016-12-09 12:13:13,613 got process_message
2016-12-09 12:13:13,717 got process_reconnect_url
2016-12-09 12:13:13,819 got process_presence_change
2016-12-09 12:13:13,921 got process_pong
2016-12-09 12:13:17,247 got process_pong
2016-12-09 12:13:21,278 got process_pong
2016-12-09 12:13:25,208 got process_pong
2016-12-09 12:13:29,240 got process_pong
2016-12-09 12:13:33,267 got process_pong
2016-12-09 12:13:37,299 got process_pong
2016-12-09 12:13:41,228 got process_pong
2016-12-09 12:13:45,254 got process_pong
at around 12:13:30 i sent: “update USB_EG_Windfang_01 OFF
”
.item
Switch USB_EG_Windfang_01 "USB: Hausnummer"
slackhab.py
import time
import xml.etree.ElementTree as xml
crontable = []
outputs = []
debug = True
openhab_url = 'http://192.168.xxx.xxx:8080' // my openHAB-URL
slackhab_user_id = "Uxxx" // the Userid from the bot in slack
headers = { 'Content-Type': 'text/plain' }
def process_message(data):
print_debug(str(data))
# check we have sufficient details
if 'channel' not in data or 'user' not in data or 'text' not in data:
return
channel = data['channel']
(...)
My guess is, the Connection between slack and the RTM-bot isn’t configured? I tried to pack all defs in slackhab.py in a class and reference it in rtmbot.conf (see escaped pluginname in rtmbot.conf)
Now I get an error in the rtmbot.log like this:
2016-12-09 12:22:21,087 Initialized in: /usr/local/bin
2016-12-09 12:22:21,111 Starting new HTTPS connection (1): slack.com
2016-12-09 12:22:21,763 "POST /api/rtm.start HTTP/1.1" 200 4529
2016-12-09 12:22:22,402 Loading plugins
2016-12-09 12:22:22,406 Importing plugins.slackhab.openHABPlugin
2016-12-09 12:22:22,429 Plugin registered: <plugins.slackhab.openHABPlugin object at 0x76231ed0>
2016-12-09 12:22:22,430 Registering jobs for openHABPlugin
2016-12-09 12:22:22,430 No jobs registered for openHABPlugin
2016-12-09 12:22:22,432 got process_hello
2016-12-09 12:22:22,534 got process_presence_change
2016-12-09 12:22:22,638 got process_message
2016-12-09 12:22:22,639 Problem in Plugin Class: openHABPlugin: process_message
{u'text': u'from repeat1 "update USB_EG_Windfang_01 OFF" in channel Dxxx', u'ts': u'14xx.xx', u'user': u'Uxx', u'reply_to': None, u'type': u'message', u'channel': u'Dxx}
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rtmbot/core.py", line 205, in do
func(data)
TypeError: process_message() takes exactly 1 argument (2 given)
2016-12-09 12:22:22,743 got process_reconnect_url
2016-12-09 12:22:22,845 got process_presence_change
2016-12-09 12:22:22,947 got process_pong
2016-12-09 12:22:26,271 got process_pong
2016-12-09 12:22:30,299 got process_pong
2016-12-09 12:22:34,226 got process_pong
2016-12-09 12:22:38,257 got process_pong
2016-12-09 12:22:42,285 got process_pong
2016-12-09 12:22:46,213 got process_pong
2016-12-09 12:22:50,241 got process_pong
2016-12-09 12:22:54,270 got process_pong
2016-12-09 12:22:58,299 got process_pong
2016-12-09 12:23:02,223 got process_pong
2016-12-09 12:23:06,254 got process_pong
2016-12-09 12:23:10,282 got process_pong
2016-12-09 12:23:14,208 got process_pong
2016-12-09 12:23:18,238 got process_pong
2016-12-09 12:23:22,261 got process_pong
2016-12-09 12:23:26,292 got process_pong
2016-12-09 12:23:30,219 got process_pong
2016-12-09 12:23:34,247 got process_pong
2016-12-09 12:23:38,277 got process_pong
2016-12-09 12:23:42,300 got process_pong
2016-12-09 12:23:46,230 got process_pong
2016-12-09 12:23:48,949 got process_user_typing
2016-12-09 12:23:50,260 got process_pong
2016-12-09 12:23:54,288 got process_pong
2016-12-09 12:23:55,198 got process_user_typing
2016-12-09 12:23:57,318 got process_message
2016-12-09 12:23:57,319 Problem in Plugin Class: openHABPlugin: process_message
{u'text': u'update Sensoren_Temp_SpOben 54.1', u'ts': u'1xx.xx', u'user': u'Uxx', u'team': u'Txx', u'type': u'message', u'channel': u'Dxx'}
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rtmbot/core.py", line 205, in do
func(data)
TypeError: process_message() takes exactly 1 argument (2 given)
2016-12-09 12:23:58,229 got process_pong
first item “USB_EG_Windfang_01
” is a SWITCH item, second item “Sensoren_Temp_SpOben
” is a NUMBER item.
So, where’s my error here? Thanks for help!