Triggering every 'X' minutes

Running 0.49 and getting an error on running a command every ‘x’ minutes

2017-07-21 12:46:00 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py”, line 101, in async_render
return self._compiled.render(kwargs).strip()
File “/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
File “/srv/homeassistant/lib/python3.5/site-packages/jinja2/sandbox.py”, line 385, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: ‘dict object’ has no attribute ‘to_state’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/tasks.py”, line 239, in _step
result = coro.send(None)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/init.py”, line 340, in async_trigger
yield from self._async_action(self.entity_id, variables)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/init.py”, line 430, in action
yield from script_obj.async_run(variables)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 151, in async_run
yield from self._async_call_service(action, variables)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py”, line 181, in _async_call_service
self.hass, action, True, variables, validate_config=False)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 74, in async_call_from_config
config[CONF_SERVICE_DATA_TEMPLATE]))
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 70, in _data_template_creator
for key, item in value.items()}
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 70, in
for key, item in value.items()}
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py”, line 72, in _data_template_creator
return value.async_render(variables)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py”, line 103, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: ‘dict object’ has no attribute ‘to_state’

Automation code:

automation old:
  - alias: Office AC Power
    trigger:
      - platform: time
        minutes: '/1'
        seconds: 00
    condition: 
      - condition: state 
        entity_id: input_boolean.officeacon 
        state: 'off' 
#        for:
#          minutes: 1
#      - condition: numeric_state
#        entity_id: sensor.office_ac_power_power
#        above: 0
##        for:
##          minutes: 1
    action:
      - service: notify.notify
        data_template:
          message: >
            Office power detected by {{ trigger.to_state.attributes.friendly_name }} but AC should be off!
      - service: climate.set_operation_mode
        entity_id: climate.office_ac_climate_cooling_1
        data:
          operation_mode: 'Off'

@Ch1ll4x

What does it say if you run hass --script check_config from the virtualenv?

(homeassistant) homeassistant@hamaster:~/.homeassistant$ hass --script check_config
Testing configuration at /home/homeassistant/.homeassistant
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up introduction
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up logger
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain introduction took 0.5 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up http
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up recorder
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain logger took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain http took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain recorder took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up websocket_api
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up api
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up history
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain websocket_api took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain api took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain history took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up frontend
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setup of domain frontend took 0.0 seconds.
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up group
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up zwave
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up updater
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up sensor
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up telegram_bot
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up discovery
2017-07-21 13:09:39 INFO (MainThread) [homeassistant.setup] Setting up conversation
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up input_boolean
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up notify
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up sun
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up lutron_caseta
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain group took 0.4 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain zwave took 0.4 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain updater took 0.3 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain sensor took 0.3 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain telegram_bot took 0.2 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain discovery took 0.2 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain conversation took 0.2 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up zone
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain input_boolean took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain notify took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain sun took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain lutron_caseta took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up config
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up tts
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up media_player
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up logbook
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain zone took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up automation
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain config took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain tts took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain media_player took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain logbook took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain automation took 0.0 seconds.
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setting up device_tracker
2017-07-21 13:09:40 INFO (MainThread) [homeassistant.setup] Setup of domain device_tracker took 0.0 seconds.
(homeassistant) homeassistant@hamaster:~/.homeassistant$

Guessing it’s because your trigger platform is time not state. So when your template is trying to use to_state it doesn’t make sense (it wasn’t triggered by a state, it was triggered by time, hence the no attribute ‘to_state’ error). What value are you trying to get with

{{ trigger.to_state.attributes.friendly_name }}

Also see https://home-assistant.io/docs/automation/templating/
For time, your option is trigger.now which will return the DateTime object that triggered the automation (probably not what you want…)

Is that automation showing triggered in the logbook every minute?

I’m following this, I need it to trigger every minute or so.

Exactly correct, every minute the log gets a copy of the error block

Try reading my post again. I never said you shouldn’t use a time based automation. I said the error is coming from your template config.

Error =

homeassistant.exceptions.TemplateError: UndefinedError: ‘dict object’ has no attribute ‘to_state’

Where do you see ‘to_state’ ?
Here --> Office power detected by {{ trigger.to_state.attributes.friendly_name }}

1 Like

@azeroth12 is correct it in your action.

Ah! You guys are brilliant I feel like a fool. I can’t believe I missed that.

Big thanks!!!

1 Like