Hi,
I have the home automation base on a WAGO PLC with modbus support.
I try to describe my scenario.
The state on/off of a light is stored as unsigned int in a byte of a specific address. Each address contains the state of 2 different lights (16 bit or 8+8 bit or two different byte)
I created each light’s binary sensor with the split function of a multi register sensor as below and it works fine.
modbus:
name: casa
type: tcp
host: !secret domotica
port: 502
sensors:
To change the state of a light I need to write an int value (255) in two different registers, one to switch on the light and other one to switch off it. It works fine, but only for the light managed by the first byte (first 8 bits) of the address. I don’t know how to write the 255 int value in the second byte of the address (second 8 bits).
Hi,
as far as I understood modbus (I use it from within a C-program) simply set the leading bits to 1 as well.
So for your example with 255 the lower eight bits are all set to “1” and the upper ones are zero. Instead of sending 255 (0000000011111111) you should send 65,535 (1111111111111111) if you want to use both or 65,280 (1111111100000000) just for the second one.
Give it a try, I had to do try and error a lot with this modbus stuff. In the end it is not too complicated.
I need to change only the second byte (or second group of 8 bits) without changing the first one.
A part from that, I still don’t know how to set the modbus.write_register service of ha to do this.
As I am currently as well trying to configure modbus I just realized there might not be a “read” function… strange.
In this case I am out of ideas, indeed. I would just suggest to keep track of all changes so you should always know if the light is on or not. And set the register accordingly.
I will have to go through the basic steps of configuring modbus on hoassio. Look like this is a strange implementation. I am currently struggling with the basics here. How to read a modbus sensor???
Another addition from me as I am trying to get it up and running, too.
There seems to be not explicit “read” command. When configuring a sensor you have to enter its registeraddress which will be read then.
To write you can enter a different address as shown here. “target_temp_register”.
Yes, there isn’t a specific “read” command neither an HA modbus service to try readings. The only solution is to define modbus sensors (or binary_sensors, switch and so on) based on which you have to do and based on your modbus PLC specifications (If you need some help, I could try to help you) .
To do what you said in you post about tracing all changes, the solution is to define specific sensors for the first byte and second one and based on the value of that sensors do the write with the specific value.
At the moment, the solution of 255 (0000000011111111) and 65280 (1111111100000000) works for me. I noticed that when I use the specific registers to change the state (eg: light) by writing 255, they return to 0 after action execution in PLC.
I have not tried using RESTA API but using MQTT works fine. Although this is not really a solution as I have devices which do not offer MQTT so am I stuck with modbus…
I notice that from the first code you posted and the second one you changed the input_type property of the sensor.
Same error with input_type: holding?
From documentation: “Both serial line parameters and TCP listening port (502 by default) can be configured – see Configurable parameters description. The sensor supports only a single open TCP connection at once.”
May be you have to enable/configure modbus support on sensor?
The sensor support only a single open TCP connection: sure that there are not any other modbus client connected?
name: home
type: tcp
host: xxx.xxx.xxx.xxx
port: 502
Other parameters are for serial connection. I think the “rtuovertcp” value is deprecated. Try using “tcp” instead.
“No response” means that the modbus controller doesn’t correctly respond.
About “input_type”: have you try to set “holding” ?