question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in creating sensors: 'TypeError: list indices must be integers or slices, not str'

See original GitHub issue

Powercalc: v0.8.1 HA Core Version: core-2021.9.5

yaml:

powercalc:
  scan_interval: 00:05:00 #Each minute
  create_energy_sensors: true
  power_sensor_naming: "{} power"
  energy_sensor_naming: "{} kWh"
  create_utility_meters: true
  utility_meter_types: daily
sensor:
  - platform: powercalc 
    entity_id: light.bathroom_lights_template
    multiply_factor: 3
    manufacturer: ecosmart
    model: ZBT-A19-CCT

The template light:

light.bathroom_lights_template:

min_mireds: 153
max_mireds: 370
supported_color_modes:
  - color_temp
friendly_name: Bathroom Lights
supported_features: 35

The same light info from developer tools template editor:

{{ states.light | selectattr('entity_id', 'eq' , 'light.bathroom_lights_template') | list }}

[<template TemplateState(<state light.bathroom_lights_template=off; min_mireds=153, max_mireds=370, supported_color_modes=['color_temp'], friendly_name=Bathroom Lights, supported_features=35 @ 2021-09-24T18:12:21.255437-06:00>)>]

The error:

2021-09-24 18:12:22 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/powercalc/sensor.py", line 198, in async_setup_platform
    entities.extend(await create_individual_sensors(hass, merged_sensor_config))
  File "/config/custom_components/powercalc/sensor.py", line 241, in create_individual_sensors
    power_sensor = await create_power_sensor(
  File "/config/custom_components/powercalc/sensor.py", line 359, in create_power_sensor
    await calculation_strategy.validate_config(source_entity)
  File "/config/custom_components/powercalc/strategy_lut.py", line 214, in validate_config
    supported_color_modes = source_entity.capabilities[
TypeError: list indices must be integers or slices, not str

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
backcountrymountainscommented, Sep 27, 2021

Thanks! The Ecosmart bulbs have a terrible zigbee implementation that has issues when too many zigbee commands are sent. I had to make template lights that send zigbee cluster commands directly to zigbee groups of ecosmart lights with some millisecond delays added in to get the bulbs to work well. Template lights solved all of the zigbee issues I was having with the bulbs.

For zigbee bulbs generally, I’ve found that using zigbee groups is better than using HA light groups, because simultaneous turn on/off commands are part of the zigbee protocol, thus the lights will turn on/off at the exact same time, whereas with HA light groups some bulbs turn on slightly before or after others, which is unpleasant in fixtures that contain multiple bulbs.

0reactions
bramstrokercommented, Sep 27, 2021

Thanks for clarifying. So it’s working correctly for you now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: list indices must be integers or slices, not str
This type error occurs when indexing a list with anything other than integers or slices, as the error mentions. Usually, the most straightforward...
Read more >
TypeError: list indices must be integers or slices ... - STechies
TypeError: list indices must be integers or slices, not str. Each element in a list in Python has a unique position. This position...
Read more >
TypeError: list indices must be integers or slices, not str
You can solve the error “typeerror: list indices must be integers or slices, not str” by making sure that you access items in...
Read more >
TypeError: list indices must be integers or slices, not str
First, array_length should be an integer and not a string: array_length = len(array_dates). Second, your for loop should be constructed ...
Read more >
Fix Python TypeError: List Indices must be Integers or Slices ...
If you come across an error like this: TypeError: list indices must be integers or slices, not str? Do not worry, it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found