Notify on input_select

Hi,
I wanted to know how I can set up a notify based on a input_select… for example I have this input select:

who_cooks:
  name: Who cooks today
  options:
    - aa
    - bb
    - cc
  initial: aa

Now I want a notify… so I need to set up an automation like these… but don’t work…

 alias: Who Cook
  trigger:
    platform: state
    entity_id: input_select.who_cooks
  action:
    - service: notify.homenicoassistant_bot
      data:
        message: "Today Cook {{ trigger.entity_id }}"

but it don’t work every time I’ll change the input slider. Anyone can help me to understand how to do it?

Hi @Ciquattro, please give
message: "Today Cook {{ trigger.to_state.state }}"
a try.

Edit:
Btw. your automation should look like:

- alias: Who Cook
  trigger:
    platform: state
    entity_id: input_select.who_cooks
  action:
    - service: notify.homenicoassistant_bot
      data:
        message: "Today Cook {{ trigger.to_state.state }}"

dont’ work… don’t know why… maybe I have to try with

platform: event

Any error in the logs?
Does your notify work?
Developer Tools -> Services
Domain: notify
Service: homenicoassistant_bot
{ "message": "Text of message" }

[homeassistant.components.automation] Executing Who Cook
17-04-11 17:31:01 ERROR (Thread-10)
17-04-11 17:37:40 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: domain=automation, name=Who Cook, message=has been triggered, entity_id=automation.who_cook>
17-04-11 17:37:40 INFO (MainThread) [homeassistant.helpers.script] Script Who Cook: Running script
17-04-11 17:37:40 INFO (MainThread) [homeassistant.helpers.script] Script Who Cook: Executing step call service
17-04-11 17:37:40 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=notify, service_data=message=Today Cook {{ trigger.to_state.state }}, service_call_id=139955226012136-11, service=homenicoassistant_bot>
17-04-11 17:37:40 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139955226012136-10>
17-04-11 17:37:40 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 139954092174640: Sending {'event': {'time_fired': datetime.datetime(2017, 4, 11, 15, 37, 40, 892765, tzinfo=<UTC>), 'event_type': 'logbook_entry', 'data': {'domain': 'automation', 'name': 'Who Cook', 'message': 'has been triggered', 'entity_id': 'automation.who_cook'}, 'origin': 'LOCAL'}, 'id': 19, 'type': 'event'}
17-04-11 17:37:40 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 139954092174640: Sending {'event': {'time_fired': datetime.datetime(2017, 4, 11, 15, 37, 40, 903182, tzinfo=<UTC>), 'event_type': 'call_service', 'data': {'domain': 'notify', 'service': 'homenicoassistant_bot', 'service_data': {'message': 'Today Cook {{ trigger.to_state.state }}'}, 'service_call_id': '139955226012136-11'}, 'origin': 'LOCAL'}, 'id': 19, 'type': 'event'}
17-04-11 17:37:40 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/template.py", line 99, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.5/site-packages/Jinja2-2.9.6-py3.5.egg/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.5/site-packages/Jinja2-2.9.6-py3.5.egg/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.5/site-packages/Jinja2-2.9.6-py3.5.egg/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.5/site-packages/Jinja2-2.9.6-py3.5.egg/jinja2/sandbox.py", line 385, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "uvloop/future.pyx", line 372, in uvloop.loop.BaseTask._fast_step (uvloop/loop.c:112669)
  File "/usr/src/app/homeassistant/core.py", line 1016, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/src/app/homeassistant/components/notify/__init__.py", line 133, in async_notify_message
    kwargs[ATTR_MESSAGE] = message.async_render()
  File "/usr/src/app/homeassistant/helpers/template.py", line 101, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined

That’s not much!
What about the notify service?
I assume there’s the problem.

notification component work… I have a lot of other automation and they are working atm

that’s the solution:

  alias: Who Cook
  trigger:
    platform: state
    entity_id: input_select.who_cooks
  action:
    - service: notify.homenicoassistant_bot
      data_template:
        message: >
           "Today Cook {{ trigger.to_state.state }}"
1 Like

:grin: Sometimes…

1 Like