Filter for sensor fails

First: I just installed Home Assistant (coming from smarthomeng) and am pretty impressed with all the components that are available out of the box.
The first “thing” I want to try is my power inverter that the modbus component could read just like that :slight_smile:
I’ve created e.g. this:

- platform: modbus
  scan_interval: 30
  registers:
  - name: SMA Leistung
    hub: sma
    slave: 3
    register: 30775
    unit_of_measurement: W
    #register_type: input
    count: 2
    device_class: power
    data_type: int

- platform: filter
  name: "Leistung"
  entity_id: sensor.sma_leistung
  filters:
    - filter: range
      lower_bound: 0.0

sensor.sma_leistung is correctly shown in the entities and has a value. I still get the following error:

Logger: homeassistant.components.sensor
Source: components/filter/sensor.py:189
Integration: Sensor (documentation, issues)
First occurred: 10:06:04 PM (1 occurrences)
Last logged: 10:06:04 PM

Error while setting up filter platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 292, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 449, in _async_add_entity
    await entity.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/filter/sensor.py", line 276, in async_added_to_hass
    filter_sensor_state_listener(self._entity, prev_state, state, False)
  File "/usr/src/homeassistant/homeassistant/components/filter/sensor.py", line 189, in filter_sensor_state_listener
    filtered_state = filt.filter_state(copy(temp_state))
  File "/usr/local/lib/python3.7/copy.py", line 106, in copy
    return _reconstruct(x, None, *rv)
  File "/usr/local/lib/python3.7/copy.py", line 293, in _reconstruct
    setattr(y, key, value)
AttributeError: can't set attribute

I suspect the error has something to do with the data that is already in the database. The power inverter shuts down in the night and reports -2147483648. This alone should not cause the above exception and the verbose logging did not show a hint to the original problem :frowning:

Could somebody point me in the right direction to figure out why the filter is not working? I already deleted the database (first stopping hass) and it didn’t help.

Doesn’t really help much, but:

Thanks @Troon. It does help, as I know that this is most likely not my error and I can continue evaluating Home Assistant.
For testing I will try an older version.
Update:
I :heart: Docker. homeassistant/raspberrypi3-homeassistant:0.111.4 is working
Update 2:
Now my KNX configuration doesn’t work anymore :roll_eyes: Let’s wait for another update.

There was no change to the Knx integration since 0.110. are you getting an error?

Layer 8 problem. sry for the false alarm. I am just starting with Home Assistant.
Now I got KNX, MQTT and Modbus working. So not bad for a start :slight_smile:

you could do the same with a template sensor, e.g. two versions of how you could handle the -2^31:

- platform: template
  sensors:
    dc_power_stp8_o:
      friendly_name: "DC power STP8.0 O"
      icon_template: mdi:solar-power
      unit_of_measurement: W
      device_class: power
      value_template: >-
          {% if states('sensor.dc_leistung_stp8_o')|int >= 0 %}
          {{ states('sensor.dc_leistung_stp8_o') }}
          {% else %}
            "unavailable"
          {% endif %}
      availability_template: >-
          {% if not is_state("sensor.dc_leistung_stp8_o", "unavailable") %}
            true
          {% endif %}
    dc_power_stp8_w:
      friendly_name: "DC power STP8.0 W"
      icon_template: mdi:solar-power
      unit_of_measurement: W
      device_class: power
      value_template: >-
          {% if states('sensor.dc_leistung_stp8_w')|int >= 0 %}
          {{ states('sensor.dc_leistung_stp8_w') }}
          {% else %}
          0
          {% endif %}

But what I’d rather have is some HA modbus config option to set the “i’m not doing anything” value of -2,147,483,648 = 2^31 to e.g. state = unavailable or offline, or non-operational. Not sure if other devices have a similar behaviour, or if this is exclusive to SMA. But the inverter can be turned on and have a output of 0, or it goes in night mode when there is no voltage on the string at all.

1 Like