[Solved] Automation template causes unhashable error

I’m trying to get a negative condition to work in my automation, so I have been playing with templates…

However, whenever I try to check that the configuration is valid (from the Server Controls page), nothing really happens (the Check Configuration’s “busy status” thing just keeps rotating.)

Looking at the log, I’m causing this error:

2020-05-18 22:26:16 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 125, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/core.py", line 29, in post
    errors = await async_check_ha_config_file(request.app["hass"])
  File "/usr/src/homeassistant/homeassistant/config.py", line 830, in async_check_ha_config_file
    res = await check_config.async_check_ha_config_file(hass)
  File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 148, in async_check_ha_config_file
    p_validated = component_platform_schema(p_config)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 208, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 283, in _exec
    v = func(v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 205, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 285, in _exec
    v = func(path, v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 635, in validate_sequence
    cval = validate(index_path, value)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 732, in key_value_validator
    if key_value not in value_schemas:
TypeError: unhashable type: 'collections.OrderedDict'

The yaml / jinja causing the error appears to be simply:

    - condition:  
        condition: template
        value_template: "{{ not is_state('input_select.house_mode', 'Away') }}"

removing that, or changing it to a standard state condition, then everything’s good…

IMHO a syntax / coding error appears to be causing quite a fault in the system, which should be at least caught and returned as “Configuration is not right!” :slight_smile:

I see that this was occuring recently with This forum post, so perhaps there’s a bug here?

Just for completeness, my actual code is:

- id: 'EveningLampsOnSummer'
  alias: Summer Evening Lamps (On)
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: '4.0'
  condition:
    - condition: time
      after: '17:45'
      before: '22:14'
    - condition:  
        condition: template
        value_template: "{{ not is_state('input_select.house_mode', 'Away') }}"
  action:
  - entity_id: switch.hall_socket_1_relay
    service: switch.turn_on

Pointers?

The statement looks (nearly) spot on to me. (it’s home and not_home, not home and away - always check elements in the template editor)
What does the template editor say ?

Have you tried enclosing the sub elements in brackets ?

What about if you change the statement to (something like) : -

"{{ not (states('input_select.house_mode') == 'not_home')}}" 

See popboxgun’s reply below

Too many condition:

 condition:
    - condition: time
      after: '17:45'
      before: '22:14'
    - condition: template
      value_template: "{{ not is_state('input_select.house_mode', 'Away') }}"
1 Like

Good catch !

Mainly because it’s an input_select (not a device_tracker) so not ‘away’ is TOTALLY legit (my apologies)

What do they say about ASSumptions ?

Nice!

Thanks!

Sometimes we stare at things too much and become blind to the syntax :wink:

Still… it’s strange that HA just explodes - that should cause a syntax error for the user (me), not an exception in the code…

Anyway, thanks @popboxgun

1 Like

And just to add… the latest release now has “not” functionality :crazy_face:
Release Notes: 0.110