Modbus help - write a register with calculated value

Hello
I am controlling a CCN (carrier) HVAC using Homeassistant. To stop short cycling of compressors, I write setpoints using the following automation. (Think of setpoint as thermostat temperature).

If Entering water temp (think room temp) is above 19, write 11 to holding register. (This switches on compressor and it slowly brings temp to 11).

The moment temp hits 11, write 19 to holding register (this stops the compressor as set temp is reached).

Worked very well. But i learnt the complexities of a chiller later on and ended up learning zm and szm (Its a multiple compressor unit). Long story - My approach of setting simple two setpoints is wrong. I need to “guide” the unit from 19 to 11 in steps - or it will switch on ALL the compressors (its a multi compressor unit). The unit can calculate this guide itself called sensor.setpoint- I just need to write this to register on frequent intervals when the unit is running.

So I need to do the following -
When the unit has started running (sensor.runstate=Running), do the following -
Write register 2 as a value which needs to be calculated as - sensor.setpoint+6
Do write this value every few seconds(say 10) till the sensor.runstate=Running.

My question -
How do I write to a register a calculated value (sensor.setpoint + 6)

How do I make sure this automation is in working state after reboot.
Do I make a combination of scene/automation/script?

Here is my current automation
trigger:

  • platform: state
    entity_id:
    • sensor.runstate
      from: null
      to: Running
      for:
      hours: 0
      minutes: 0
      seconds: 5
      condition:
      action:
  • service: modbus.write_register
    data:
    address: 2
    value: 12
    mode: single

You see how your pasted code is virtually unreadable compared with other examples around the forum? Please format it properly: see here:

or just surround your code with three backticks:

```
CODE GOES HERE
```

Then indentation, quoting and hyphens are preserved and we can see the code properly.

IF modbus.write_register supports templates in its value parameter, then you need this:

value: "{{ states('sensor.setpoint')|int(0) + 6 }}"

Your automation will only trigger when the state of the runstate sensor changes to “Running” from something else, so it’ll need more work to get to the iterative process you want.

Perhaps look up wait…until in the script documentation, noting that an automation is simply a script with a trigger:

Thank you<- will try the template.
I cut and paste in Quote/unquote but missed it somewhere.

I asked for help as this is 30T chiller unit - so experimenting is a bit … dangerous.
A bit of spoonfeeding by experts is always helpful.

Another question is how does automation mode work. Right now its single. Will making it to restart work?
(i read docs - but am still confused)

No, you need to either:

  • build a loop into your action using wait…until
  • find another trigger to make the next change.

A trigger is an event. If the runstate does not change from “Running”, the automation will run once and stop until next time the runstate becomes “Running”.

If this chiller is dangerous, you will need to be very careful with your language. I believe you mean “while the runstate is Running” or “until the runstate is not Running”.