Writing to Modbus registers

I have been using Homeseer for ~20years and I am now setting up my HA. It looks really impressive when compared with HS. I have several programmable controllers with Modbus interface each connected to a Moxa tcp/ip-rs485 converter.

I have now managed to setup HA for reading a temp value from an extra controller which I’m using for testing purposes. This controller is working as a thermostat now. Next step would be to change setpoints in this controller.

The difficulty is that I need to write first to MB register 130 an integer (which is the channel index) and wait until the value of this register has changed from 0XFF to 0X00. Only after this I can change the value (=setpoint) in register 132. In HS I first write e.g. integer 1 to register 130 and I have a loop reading register 130. Once it has changed to 0X00 then I can write the new setpoint to register 132. I wonder how this can be done in HA. Any ideas?

A sensor reading 130.

An automation when 130 change, do something

Thanks. As I am at the very beginning of my learning curve I don’t know yet how to do automation. In addition to the setpoint issue I would like to create a switch (on/off) and this also requires writing first to register 130 and after that to register 134. In my configuration.yaml I have

switches:
      - name: "garage heating on/off"
        slave: 1
        address: 130
        command_on: 100
        command_off: 0

I can see in the UI the switch but of course it doesn’t work because I don’t know how to write to register 134 either 0 or 100. Any help would be greatful.

1 Like

Another switch

Try first use manually various switches

For 130 you need a sensor too

Maybe 130 is a security register

In a normal way you only need “climates”

For such a complicated procedure, I don’t think switches are the way to go. I’d try creating a script and passing the target temperature as a variable to it.
The script could then use things like wait for trigger and modbus services to execute the sequence.
Unfortunately, I don’t currently have time to write an example script. Still, I hope this helps.

To read the register, you’ll probably have to create a modbus sensor. That will be polled every 10 seconds by default. To poll it sooner, you should be able to use the homeassistant.update_entity service.

1 Like

Thanks guys. I have to say I am really confused about automations and scripts. I can see that there is yaml-file for both of these but I don’t have any experience yet how to use scripts in HA.

To be more specific I have two different cases. My controller is programmed to work as a thermostat which has 6 relays.

  1. I want to create a switch to turn off all the relays. In this case I write integer 1 to Modbus register 130 and once it has changed from 0XFF to 0X00 I can write either 0 (=off) or 100 (=on) to register 132.

  2. Setpoint. In this case I write integer 2 to Modbus register 130 and once it has changed from 0XFF to 0X00 I can write a new setpoint to register 134. This will control relay 1. Similarly when changing setpoint for other relays I first write to register 130 certain integer an then to corresponding register the new setpoint.

I already know how to read temperatures from the controller (from single registers) but this is much easier because reading from a certain single register is a one step process.

So, basically I would need an example how to do a script including automations.