Input Select bug? HA mixes up values at startup

I’ve performed a couple more restarts today and have not been able to reproduce the issue.

Saw this in the log this morning:

Invalid option: Forest (possible options: Off, Powerful Heat, Normal Heat, Silent Heat, Powerful Cool, Normal Cool, Silent Cool)

Again, Forest is an option for a completely unrelated input_select and nowhere in my automations do I try to select it as an option for the air-conditioner input_select.

I have opened an issue for this: https://github.com/home-assistant/home-assistant/issues/19810

I had HA in debug logging mode for a few days to try and capture one of these errors but as Murphy would have it nothing happened and debug logging was thrashing my SD card so I had to reduce the logging level.

To work around this problem I am going to add a template condition to all my automations that change input selects to ensure the option is valid.

e.g.

- id: logging_level
  alias: 'Logging Level'
  initial_state: true
  hide_entity: true
  trigger:
    platform: state
    entity_id: input_select.logging_level
  condition:
  - condition: template
    value_template: "{{trigger.to_state.state in ['error', 'warning', 'info', 'debug'] }}"
  action:
    service: logger.set_default_level
    data_template:
      level: "{{ trigger.to_state.state }}"

If you want to use this with other input selects, you could modify the condition this way.

  condition:
  - condition: template
    value_template: "{{ trigger.to_state.state in state_attr(trigger.entity_id,'options') }}"

This way, it will always work and you don’t have to hard code the options.

1 Like

Ugh. I hard coded them all this afternoon!

Thanks though. I’ll change the conditions to your version at some stage. Makes it easier if I ever update any of the input selects options.

yah, i hate hard coding things for that reason alone

Done. It wasn’t that hard with find/replace.

Interestingly I just saw this error on start up:

Error during template condition: UndefinedError: 'dict object' has no attribute 'to_state'

My input select automations do seem to be working and are not creating more of these errors.

I wonder if this strange input_select bug is being caused by some input_select not being ready before being called in an automation after a restart?

That’s possible. You may need to add another check to verify that the trigger platform is ‘state’. I’m willing to bet that HA does some funky things during startup and maybe some bad triggers get sent.

I’m not sure what you mean by this. Do you mean checking the trigger_to_state.state for ‘undefined’?

That could also work if the trigger truely isn’t defined.

But what I meant was:

trigger.platfrom == 'state'

I have to admit I have no idea what that is actually checking.

So, it’s checking the trigger object itself. Triggers are just like the data section, accept they have different data. In fact, pretty much all data passed in home assistant look’s like the data section for actions. Pretty much all state objects have attributes inside attributes etc. You just gotta know what to look for. Luckily alot of this is spelled out in the docs, it’s just burried inside areas that people don’t understand.

this pretty much shows the shape of all trigger objects:

which references state objects alot, so heres that documentation:

So, looking at that documentation, if we have this as our trigger:

trigger:
  - platform: state
    entity_id: switch.something

then our trigger will look like this, and we can access it all:

What the data would look like if it was written as a dictionary

trigger: {
  'platform': 'state',
  'entity_id': 'switch.something',
  'from_state': {'state':'off', 'attributes':{'attr1':'value'}},
  'to_state': {'state':'off', 'attributes':{'attr1':'value'}},
  'for':{'hour':0,'minute':0,'second':0}}

So when the trigger is passed to us we have access to all that. Typically you see people only looking at to_state and from_state. But we can look at everything.

to look at it all, we use dots. so…

trigger.platform #returns 'state'
trigger.entity_id #returns 'switch.something'
trigger.for.hour #returns 0
trigger.to_state.state #returns 'off'

etc

Even with that condition in all automations that change input selects I’m still getting the occasional warning in the log and today I saw this when I went to manually change an input select:

rumpus_ac_mode:
  name: Rumpus Room Aircon Control
  options:
   - 'Off'
   - Powerful Heat
   - Normal Heat
   - Silent Heat
   - Powerful Cool
   - Normal Cool
   - Silent Cool
  icon: mdi:format-list-bulleted

Someone needs to have a serious look at the input_select.select_option service.

EDIT:

Or maybe I need to check my code more closely, this is wrong but would it cause the above problem?

  action:
    - service: input_select.select_option
      data_template:   ### <-------------- Lazy copy / paste error
        entity_id: input_select.rumpus_ac_mode
        option: 'Off'

Time will tell. I’ve fixed it and reloaded my automations.

EDIT 2:

Nope. Still happening:

It’s the picture elements card. It totally screws up the input select, repeatable with any input select:

Input Select in an entities card (good):

Same input select in a picture elements card showing invalid selection:

If I manually select a valid option for the input select on the picture elements card, navigate away then back, the selection is an invalid option (not on the list) again.

Every time I tap on the icon it generates warnings in the log.

Good work! Have you ever created an Issue on github before?

Yeah I have. I found this issue and was debating putting in another as I have specific repeatable conditions and it relates more to the picture elements card than the input select. What do you reckon?

I’d put out another one in polymer. It’s lovelace’s code.

Yeah that issue I linked was moved to HA-polymer.

I think what you did in that is fine. The first post doesn’t point to the problem. Your comments do.

1 Like

The fix for this has been merged:

1 Like