Channel Not Found - Slack

I am trying to send notifications to slack but I am having some issues.

Error:
homeassistant.components.notify.slack: Could not send slack notification. Error: channel_not_found

The below are the config all within the configuration.yaml

notify config

notify:
  - name: slack
    platform: slack
    api_key: _removed_
    default_channel: '#general'
    username: "hass"

automation config

automation:
  trigger:
    platform: state
    entity_id: binary_sensor.up_stairs_motion
    state: 'on'
  action:
    service: notify.slack
    data:
      message: 'Motion Detected'
      target: ""

Thank you!

Is your bot in the room?

I believe so, General is a public room. I tried a private room called ā€˜Notificationsā€™ and invited the bot and still had the same issue.

Huh weird, when I click the trigger button it doesnā€™t work but now I am getting notifications of things happening.

I am going to have to do more testing when I get home to see what is going on.

I will update you. Thanks fadaff

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.

Can reproduce it and opened an issue.

1 Like

Iā€™m using HASSIO with 0.65.4 and Iā€™m getting this problem too.

2018-03-15 22:20:54 ERROR (SyncWorker_4) [homeassistant.components.notify.slack] Could not send notification. Error: not_in_channel

The strange thing is this happens for the below script:

  - service: notify.slack
    data:
      message: "Test Message" 

But works fine whenever I do a notification that has a File or URL attached like below. Can someone help???

  - service: notify.slack
    data_template:
      title: >
        You have Mail - Parcel Chute just opened
      message: >
        Parcel Chute just opened, {{now().strftime("%A %H:%M:%S %d-%m-%Y")}}
      data:
        file:
          path: /config/notify/FRNTMAIL.jpg

I figured out my problemā€¦ it was because the bot was not in the #general channel.

To add the bot to the channel using the slack app I simply wrote a message @mybot in the #general channel and that asked if I wanted to add the bot to the channel. After doing so my problems were resolved.