'TuyaLocalLight' object has no attribute 'device'

I am trying to some lights using scenes, depending the state of the “dumb” washing machine. I have two states, depending on power consumption stored in “input_select.washing_machine_status” as Empty and Done.

When the status of washing machine changes to done, the scene.create saves the scene of the light.office_corner_light and turns the light on and blue.

When I change the washing_machine_status to empty, the light should return to the saved state.

I have the following automation:

alias: Washing machine state modes
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.washing_machine_status
    id: done
    to: Done
  - platform: state
    entity_id:
      - input_select.washing_machine_status
    id: empty
    to: Empty
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - done
        sequence:
          - service: scene.create
            metadata: {}
            data:
              scene_id: office_corner_before
              snapshot_entities:
                - light.office_corner_light
          - service: light.turn_on
            metadata: {}
            data:
              rgb_color:
                - 0
                - 0
                - 255
              brightness_pct: 100
            target:
              entity_id: light.office_corner_light
            enabled: true
      - conditions:
          - condition: trigger
            id:
              - empty
        sequence:
          - service: scene.turn_on
            metadata: {}
            target:
              entity_id: scene.office_corner_before
mode: single

I can confirm that the light turns on and blue, but when I select empty, nothing happens and I get the following error log:

2024-07-19 21:23:26.395 ERROR (MainThread) [homeassistant.components.automation.washing_machine_state_modes] Washing machine state modes: Choose at step 1: choice 2: Error executing script. Unexpected error for call_service at pos 1: 'TuyaLocalLight' object has no attribute 'device'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/scene/__init__.py", line 116, in _async_activate
    await self.async_activate(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 370, in async_activate
    await async_reproduce_state(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 70, in async_reproduce_state
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 64, in worker
    await platform.async_reproduce_states(
  File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 159, in async_reproduce_states
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 146, in _async_reproduce_state
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/tuya_local/light.py", line 360, in async_turn_on
    or self._color_mode_dps.values(self.device)[0]
                                   ^^^^^^^^^^^
AttributeError: 'TuyaLocalLight' object has no attribute 'device'. Did you mean: '_device'?
2024-07-19 21:23:26.397 ERROR (MainThread) [homeassistant.components.automation.washing_machine_state_modes] Washing machine state modes: Error executing script. Unexpected error for choose at pos 1: 'TuyaLocalLight' object has no attribute 'device'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1042, in _async_choose_step
    await self._async_run_script(script)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1240, in _async_run_script
    result = await self._async_run_long_action(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1770, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 465, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 529, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/scene/__init__.py", line 116, in _async_activate
    await self.async_activate(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 370, in async_activate
    await async_reproduce_state(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 70, in async_reproduce_state
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 64, in worker
    await platform.async_reproduce_states(
  File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 159, in async_reproduce_states
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 146, in _async_reproduce_state
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/tuya_local/light.py", line 360, in async_turn_on
    or self._color_mode_dps.values(self.device)[0]
                                   ^^^^^^^^^^^
AttributeError: 'TuyaLocalLight' object has no attribute 'device'. Did you mean: '_device'?
2024-07-19 21:23:26.401 ERROR (MainThread) [homeassistant.components.automation.washing_machine_state_modes] While executing automation automation.washing_machine_state_modes
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 755, in async_trigger
    return await self.action_script.async_run(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1770, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 465, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 529, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1042, in _async_choose_step
    await self._async_run_script(script)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1240, in _async_run_script
    result = await self._async_run_long_action(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1770, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 465, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 529, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/scene/__init__.py", line 116, in _async_activate
    await self.async_activate(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/scene.py", line 370, in async_activate
    await async_reproduce_state(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 70, in async_reproduce_state
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/helpers/state.py", line 64, in worker
    await platform.async_reproduce_states(
  File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 159, in async_reproduce_states
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/light/reproduce_state.py", line 146, in _async_reproduce_state
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/tuya_local/light.py", line 360, in async_turn_on
    or self._color_mode_dps.values(self.device)[0]
                                   ^^^^^^^^^^^
AttributeError: 'TuyaLocalLight' object has no attribute 'device'. Did you mean: '_device'?

The light I am using is integrated via TuyaLocal. Any ideas what could be the cause of the issue?

Hi,
If you have a problem with a specific custom integration, your first step should be to check the original GitHub post where you found it. The people there know the product and use the software, so they can give you better help with your issue.

You might find someone here who can help, but it’s not guaranteed

Personally I only have a couple of lights that are Tuya, so the core integration gets me thru.

Also device automations are intended for machine use, and have limitations while troubleshooting them or manually editing them.
Why and how to avoid device_ids in automations and scripts.

Thanks for four input @Sir_Goodenough .

The interesting part is, that I am not using device_id only entity_id.
I’ll try my luck via GitHub, opening an issue with the integration developer.

1 Like