Problem to put sensor in a message

I am trying to send sensor value in an email.

 burglar: 
alias: Burglar Alarm
sequence:
  - service: shell_command.snapshot
  - delay:
        seconds: 1
  - service: notify.NOTIFIER_NAME
    data_template:
      title: "Temperature is"
      message: "The sun is {{ sensor.aeotec_zw100_multisensor_6_temperature_6_1  }} degrees."

I get this error message:

   17-02-03 23:15:42 ERROR (Thread-13) [netdisco.ssdp] Error fetching description at 192.168.1.17
17-02-03 23:15:56 WARNING (MainThread) [homeassistant.core] Unable to find service shell_command/snapshot
17-02-03 23:16:06 WARNING (Thread-6) [homeassistant.components.zwave] zwave not ready after 30 seconds, continuing anyway
17-02-03 23:16:07 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 99, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/jinja2/sandbox.py", line 385, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'sensor' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/script.py", line 117, in async_run
    yield from self._async_call_service(action, variables)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/script.py", line 147, in _async_call_service
    self.hass, action, True, variables, validate_config=False)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/service.py", line 88, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE]))
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/service.py", line 84, in _data_template_creator
    for key, item in value.items()}
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/service.py", line 84, in <dictcomp>
    for key, item in value.items()}
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/service.py", line 86, in _data_template_creator
    return value.async_render(variables)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 101, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'sensor' is undefined
1 Like

I have changed message to

 burglar: 
alias: Burglar Alarm
sequence:
  - service: shell_command.snapshot
  - delay:
        seconds: 1
  - service: notify.NOTIFIER_NAME
    data_template:
      title: "Temperature is"
      message: "The sun is {{ states.sensor.aeotec_zw100_multisensor_6_temperature_6_1  }} degrees."

Now I don’t get error in log but email has

The sun is <state sensor.aeotec_zw100_multisensor_6_temperature_6_1=67.6; node_id=6, battery_level=100, unit_of_measurement=°F, friendly_name=Aeotec ZW100 MultiSensor 6 Temperature @ 2017-02-03T23:40:52.232236-05:00> degrees.

How do I get just temperature value ?

1 Like

Solved. Need to have this notice .state at the end.

message: “The sun is {{ states.sensor.aeotec_zw100_multisensor_6_temperature_6_1.state }} degrees.”

If somebody can point to documentation on this it would be great.

4 Likes