Berlenz / Home-Assistant-ebus-access

Implements ebus communication in home assistant
7 stars 0 forks source link

Error when calling ebus.ebus_write #4

Open jnasholm opened 1 year ago

jnasholm commented 1 year ago

I am trying to get ebus.write working in Home Assistant 2023.3.6. Tried both in Developer Tools and in an automation based on the example code provided in the documentation. The service call results in an error and the target sensor remains unchanged. Changing the target sensor command line with the ebusctl works as expected.

Any suggestion what to try next is appreciated.

Test in Developer Tools, Services, Call Service:

service: ebus.ebus_write
data:
  entity_id: sensor.gp_rumstemperatur_installd
  value: 23

Test in automation:

automation:
  - alias: "GP ställ in rumstemperatur"
    trigger:
      platform: state
      entity_id: input_number.gaspanna_rumstemperatur
    action:
      - service: ebus.ebus_write
        data:
          entity_id: sensor.gp_rumstemperatur_installd
          value: "{{ states('input_number.gaspanna_rumstemperatur') | float(0) | round(1) }}"

Same result from both tests. Error description in Home Assistant Core Logs:

GP ställ in rumstemperatur: Error executing script. Unexpected error for call_service at pos 1: 'in <string>' requires string as left operand, not NoneType
While executing automation automation.gp_stall_in_rumstemperatur
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1851, in _execute_service
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ebus/sensor.py", line 85, in ebus_write
    target_sensors = [
  File "/config/custom_components/ebus/sensor.py", line 86, in <listcomp>
    sensor for sensor in sensors if sensor.entity_id in entity_ids
TypeError: 'in <string>' requires string as left operand, not NoneType
Berlenz commented 1 year ago

I have tested the following configuration and found no problem. Home Assistant: version 2023.4.2

input_number: #https://www.home-assistant.io/integrations/input_number/
  slider_heating_manual_setpoint:
    name: 'Slider heating manual setpoint'
    min: 0
    max: 35
    step: 0.5
    unit_of_measurement: '°C'

automation:
  - alias: 'Set heating manual setpoint by slider'
    trigger:
      platform: state
      entity_id: input_number.slider_heating_manual_setpoint
    action:
      service: ebus.ebus_write
      data:
        entity_id: sensor.heatpump_temperature_heating_manual_setpoint
        value: "{{states('input_number.slider_heating_manual_setpoint')}}"

When the slider in home assistant is moved, the manual heating temperature in the heat pump is set to the value of the slider.

jnasholm commented 1 year ago

Managed to get ebus_write to work after a bit of experimenting. Seems like if a sensor fails to initialize due to misconfiguration, wrong circuit or data type for example, it is still on the list of sensors but with an entity_id "NoneType". Maybe some condition could skip such failed sensor entries in the code? sensor for sensor in sensors if sensor.entity_id in entity_ids