If I call Developer tools the slack notify - everything works perfect. My api_key already changed.
file notify.yaml:
- platform: slack
name: notify
api_key: 'xoxb-75081053286-cDkbuJNwQb78P1GfR12vxQUN'
default_channel: '#home-assistance'
username "hass"
I have error in error log:
> 16-10-11 12:58:43 homeassistant.core: BusHandler:Exception doing job
> Traceback (most recent call last):
> File "/srv/hass/lib/python3.4/site-packages/homeassistant/core.py", line 1224, in job_handler
> func(*args)
> File "/srv/hass/lib/python3.4/site-packages/homeassistant/core.py", line 1087, in execute_service
> service_handler.func(service_call)
> File "/srv/hass/lib/python3.4/site-packages/homeassistant/components/notify/__init__.py", line 111, in notify_message
> notify_service.send_message(**kwargs)
> File "/srv/hass/lib/python3.4/site-packages/homeassistant/components/notify/slack.py", line 76, in send_message
> for target in targets:
> TypeError: 'NoneType' object is not iterable
this is 76 row:
for target in targets:
the function:
def send_message(self, message="", **kwargs):
"""Send a message to a user."""
import slacker
targets = kwargs.get(ATTR_TARGET, [self._default_channel])
data = kwargs.get('data')
attachments = data.get('attachments') if data else None
for target in targets:
try:
self.slack.chat.post_message(target, message,
as_user=self._as_user,
username=self._username,
icon_emoji=self._icon,
attachments=attachments,
link_names=True)
except slacker.Error as err:
_LOGGER.error("Could not send slack notification. Error: %s",
err)
I see that something wrong in:
targets = kwargs.get(ATTR_TARGET, [self._default_channel])
What can be wrong?
I have check the kwargs dict:
kwargs: {'data': None, 'target': None}
So it looks that something wrong not here but before in other functions. There is no ātargetā key dict value. That is why system goes to the error.
In case of using DevTool:
notify/notify with { "target": "#home-assistance", "message": "testing slack" }
we have everything good and dict is:
kwargs: {'data': None, 'target': ['#home-assistance]}
So why with my automation it is not works:
######################################################
#automation 9:
- alias: Update family home
######################################################
trigger:
- platform: state
entity_id: group.family
to: 'home'
for:
hours: 0
minutes: 2
seconds: 0
action:
service: notify.notify
data:
message: 'Somebody came home!'
So fix it by adding simple condition.
after:
targets = kwargs.get(ATTR_TARGET, [self._default_channel])`
add this two lines:
if targets == None:
targets = [self._default_channel]
And will be waiting for new release. Many thanks.