core: MQTT light doesn't work in 115.3

The problem

MQTT light seems to stop working after upgrading from 114.4 to 115.0.

Environment

arch x86_64
dev false
docker true
hassio false
installation_type Home Assistant Container
os_name Linux
os_version 4.15.0-99-generic
python_version 3.8.5
timezone Europe/Amsterdam
version 0.115.3
virtualenv false
  • Home Assistant Core release with the issue: 0.115.0 to 0.115.3
  • Last working Home Assistant Core release (if known): 0.114.4
  • Operating environment (OS/Container/Supervised/Core): Ubuntu/docker/
  • Integration causing this issue: MQTT Light
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/light.mqtt

Problem-relevant configuration.yaml

light:
- platform: mqtt
  schema: json
  name: Living room ceiling
  state_topic: "milight/states/0x14D9/rgb_cct/1"
  command_topic: "milight/0x14D9/rgb_cct/1"
  brightness: true
  rgb: true
  retain: true

automation:
- alias: Livingroom wall switch 1 on
  trigger:
    - platform: state
      entity_id: sensor.0x000d6f0013f04062_action
      to: 'on_1'
  action:
    - service: light.turn_on
      entity_id: light.living_room_ceiling
      data_template:
        brightness_pct: 100

Traceback/Error logs

2020-09-25 16:26:31 ERROR (MainThread) [homeassistant.components.automation.livingroom_wall_switch_1_on] Livingroom wall switch 1 on: Error executing script. Unexpected error for call_service at pos 1: 'light.living_room_ceiling'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 206, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 413, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1315, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1350, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 424, in entity_service_call
    entity_ids.remove(entity.entity_id)
KeyError: 'light.living_room_ceiling'
2020-09-25 16:26:31 ERROR (MainThread) [homeassistant.components.automation.livingroom_wall_switch_1_on] While executing automation automation.livingroom_wall_switch_1_on
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 426, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 944, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 198, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 206, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 413, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1315, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1350, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 424, in entity_service_call
    entity_ids.remove(entity.entity_id)
KeyError: 'light.living_room_ceiling'

Additional information

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 30 (12 by maintainers)

Most upvoted comments

A minimal patch, @bdraco is working on something more refined:

diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py
index 777af5f013..c1d47da563 100644
--- a/homeassistant/helpers/entity_platform.py
+++ b/homeassistant/helpers/entity_platform.py
@@ -7,7 +7,7 @@ from types import ModuleType
 from typing import TYPE_CHECKING, Callable, Coroutine, Dict, Iterable, List, Optional

 from homeassistant import config_entries
-from homeassistant.const import DEVICE_DEFAULT_NAME
+from homeassistant.const import DEVICE_DEFAULT_NAME, STATE_UNAVAILABLE
 from homeassistant.core import (
     CALLBACK_TYPE,
     ServiceCall,
@@ -483,6 +483,10 @@ class EntityPlatform:

         entity_id = entity.entity_id
         self.entities[entity_id] = entity
+
+        # Reserve the state in the state machine
+        self.hass.states.async_set(entity.entity_id, STATE_UNAVAILABLE)
+
         entity.async_on_remove(lambda: self.entities.pop(entity_id))

         await entity.add_to_platform_finish()