Thx @creis for your work.
I’m having troubles with the write_register service.
I can read the e3dc wallbox settings and with
{{ states('sensor.e3dc_wallbox_settings') | int // (2**N) % 2}}
(where N = a number from0-5 for the 6 Bits) I can extract the state of every single bit and created binary sensors for this. See the below Example for the state of “Use any power, not only solar” as you stated above.
- binary sensor:
- name: wbbit1
unique_id: wbbit1
state: >
{{ states('sensor.e3dc_wallbox_settings') | int // (2**1) % 2}}
Now, I’d like to change the settings with:
service: modbus.write_register
data:
address: 40087
hub: e3dc
value: 51
and I recieve the follwoing:
Logger: homeassistant
Source: components/modbus/modbus.py:398
First occurred: 13:17:15 (2945 occurrences)
Last logged: 14:55:30
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/modbus/sensor.py", line 104, in async_update
raw_result = await self._hub.async_pymodbus_call(
File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 421, in async_pymodbus_call
result = 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 "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 398, in _pymodbus_call
result = entry.func(address, value, **kwargs)
File "/usr/local/lib/python3.10/site-packages/pymodbus/client/mixin.py", line 100, in read_holding_registers
return self.execute(
File "/usr/local/lib/python3.10/site-packages/pymodbus/client/base.py", line 192, in execute
return self.transaction.execute(request)
File "/usr/local/lib/python3.10/site-packages/pymodbus/transaction.py", line 159, in execute
response, last_exception = self._transact(
File "/usr/local/lib/python3.10/site-packages/pymodbus/transaction.py", line 273, in _transact
packet = self.client.framer.buildPacket(packet)
File "/usr/local/lib/python3.10/site-packages/pymodbus/framer/socket_framer.py", line 217, in buildPacket
data = message.encode()
File "/usr/local/lib/python3.10/site-packages/pymodbus/register_read_message.py", line 31, in encode
return struct.pack(">HH", self.address, self.count)
struct.error: 'H' format requires 0 <= number <= 65535
Tried different values of course.
Actually I use a switch to perform the action as follows:
##Template switches
switch:
- platform: template
switches:
solarbetrieb:
unique_id: solarbetrieb
friendly_name: Solarbetrieb
value_template: "{{ is_state('binary_sensor.wbbit1', 'on') }}"
turn_on:
service: modbus.write_register
data:
hub: e3dc
address: 40087
value: "{{ states('sensor.e3dc_wallbox_settings') | int + 2 }}"
turn_off:
service: modbus.write_register
data:
hub: e3dc
address: 40087
value: "{{ states('sensor.e3dc_wallbox_settings') | int - 2 }}"
Which does not seem to make any problems itself. As you notice, the offset for me is -1.
Do you or others have any idea?
Cheers,
Simon