Modbus Integer Write Out

There are 7 bits in array. All bits are under address 270
In the chart they are using 0 bit but in relity it is a first bit.
Now I understand an array writes. It is a big progress. :slight_smile:
I’ll try to explain what I am interested in:
Technically each bit is controlling one relay in the swimming pool controller.
And I need to control each bit separately, leaving rest of them as they were before.
For exmple bit 4 is light, bit 6 filtration, 3 heating etc. So I would like to be able to control each system separately, without influence to remaining.
Respectivelly even more bits in one shot but rest bits shall remain as they are.
To make it easier, each bit has value 1 or 0.
One time for example switch light, ie. bit 4 to one while 6 and 4 are altready 1, next time change bit 3 to 0, while 6 is 1 and 3 is 0.
As I understood, hassio modbus is supporting both single bit and multiple bits write.
My question is how to address let say bit 4 and write value 1 in it and leave rest of bits untouched?

Okie…this is where I am at the limit of my knowledge sorry. Not up on how it all works as I said thats just how ‘I’ understood it and that could be very wrong.

There is also this in the documentation: See the “value” of an Array

Service Data Attributes

Attribute Description
hub Hub name (defaults to ‘default’ when omitted)
unit Slave address (set to 255 you talk to Modbus via TCP)
address Address of the Register (e.g., 138)
value A single value or an array of 16-bit values. Single value will call modbus function code 6. Array will call modbus function code 16. Array might need reverse ordering. E.g., to set 0x0004 you might need to set [4,0]

Glad to have helped a little but my understanding of 16-bit values is limited.

You are a far better to me.
Now we are approaching the edge. :slight_smile:

[4,0] means fourth bit, value set to 0?
If in array, for bit 4 to value 1 and bit 6 to value 0 it should be [4,1,6,0] or it simply must be two separated services for each of bits?

Edited: Otherwise - I need to specify bit and its value

Yes I agree after reading more carefully after I posted that bit from the docs.

It seems that is how you address each bit BUT then it also talks about you may need to reverse order…Yeah right!

Thanks for precise help. :+1:
I will test it ASAP.
Reverse order is for array I believe.

1 Like

@kajmaj glad I could at least point you in the right direction but I feel it was only a nudge. Post again when you have your full solution or if you get stuck along the way.

@wellsy
Tested.
address one specific bit still remains a big question. As and address of the bit is used number of bit (i.e. 0,1,2,3,4,5,6) or mask (in my case 1, 2, 4, 8, 10, 20, 40)
If I continue with 4th bit, non of [4,1] or [1,4] work while tried to write 1 to this 4th bit.
Array seems to be working somehow, at least when I needed to clear the whole register. [0,0,0,0,0,0,0] worked but for example but [1,0,0,0,0,0,0] or [0,0,0,0,0,0,1] not (resulted value of the whole register should be 64)
I must do sthg wrong but what?

@kajmaj I can only refer back again to what was discussed and was worked out in the example I posted initially. @Bard do you mind assisting in this post?

For sending an array of static values worked by using the below syntax

Now I am curious to know what the actual values of your register bits are at present?

You said:

What then happens if you send [0,0,0,0,1,0,0]

It seems that would/may fulfiill what you want to set ie: bit 4=1 and bit 6=0

@wellsy Regarding the array write there is a 3 steps process in my MODBUS device, where at at least 2 steps require write to a single bit od different registers.
If written to improper bit the device could be bricked.
I do not want to risk it before I know how to write single bit.
All my related registers are 8 bits.
one is currently: < 0100000> (decimal 32) and could be of any combination of 0 and 1 (well maybe 6 or 7 combinations). Confirmation write must be performed within 500msec, otherwise it reverts back without any change.
one of ‘confirmation’ registers is currently <1010010> and I need to change 3rd bit from the left from 0 to 1. If I do it in another bit, device could be bricked.
I have no problem with automation to do it but I am still not sure, how to hit the right bit :slight_smile:

What I know, each bit can contain 1 or 0 only. Based on it how to interpret [1,2,2] or [“1”,“2”,“2”] ? How to distinguish particular bit and its value?

Maybe my questins are silly, but rather silly up front than sorry afterwards with bricked device as the result.

I did a few more tests regarding addressing :slight_smile:
In my case:
bit address is 1,2,4,8,16,32,64 for bits 0,1,2,3,4,5,6
Value of bit is not necessary, it simply change the state.
Array of 2 or more bits (i.e. [32,16,1] ) does not work, only first bit address from left changes state(value)
So small progress, must verify array issue now

@kajmaj Do you have access to a manual for your device? Can you post a link?
Also how are you reading the values presently?

@wellsy Huh, it is a quite complex question.
As I mentioned here 21 in this topic the device is swimming pool control device Hidrolife
It can work off line or on-line using manufacturer cloud via wifi module.
Wifi module communicates with the device via MODBUS. There is 1 spare MODBUS connector available in the device
My intention is to fully cut off cloud. Simply want to have it under the control. :slight_smile:
So far I use for settings cloud (that is why I am interested in modbus write) and reading data via MODBUS TCP converter.
User manual for Hidrolife is useless regarding MODBUS.
There is available MODBUS registers description here but there are missing sequencies how to write in it.
There is a blog dealing with the integration of Hidrolife to Loxone. Fom them I am trying to gain last drops of info on write sequencies and confirmation bits combination.
That is why I know about a risk of bricked device if wrong bit is changed and trying to avoid risky experiments.
So far - MODBUS reading - fine, single bit addressing - I hope that I know (with your help :+1:), array - cannot confirm.

Ok I looked at the Modbus-registers.pdf and what I would ask of you now is a list of the registers you want to be able to read from or write to please? Interesting how it randomly jumps from english to spanish…challenging…lol!

At the moment reading from (HEX) 0x0102, 0x0106, 0x0107, 0x0411, 0x0413, 0x0416, 0x0421, 0x0504, 0x0505 and 0x010E
Need to write to 0x0411, 0x0413, 0x010E and 0x02F0 (final confirmation).There are 2 more confirmation bits somewhere in registers I do not know yet. Hopefully will know soon.
Register 0x010E is one of registers where is neccessary to write either to particular bit or in array. Two more are those “unknown” yet. Rest of registers to write it is 1 bit at a time.
Any write has to be confirmed in two more registers (sequence within defined time)

The pH level: That is read only I imagine so you just set that up as a sensor.

The water temperature sensor: That is read only I imagine so you just set that up as a sensor.

The pH control module status: That is read only I imagine so you just set that up as a sensor.

The filtering mode of the equipment: That is read only I imagine so you just set that up as a sensor.

Filtering status in manual mode (on = 1; off = 0): Read only I imagine and you should be able to read it as a binary sensor.

Heating set point temperature: So you should just be able to write the value you want to set. And you should be able to read it as a sensor.

Filtration function state. This register is read only and exposes the current state of
the filtration procedure: 0 is off and 1 is on and should just be setup as a binary sensor.

This register contains the higher limit of the pH regulation system: So you should just be able to write the value you want to set. And you should be able to read it as a sensor.
The value set in this register is multiplied by 100. This means that if we want to set
a value of 7.5, the numerical content that we must write in this register is 750.
This register must be always higher than MBF_PAR_PH2.
 To make the modification of this register persistent, execute the EEPROM
storage procedure described in global register MBF_SAVE_TO_EEPROM.

NOTE: “The value set in this register is multiplied by 100. This means that if we want to set a value of 7.5, the numerical content that we must write in this register is 750” I think there may be a typo here: So register is multiplied by 100 may be register is divided by 100? But that needs to be clarified?

This register contains the lower limit of the pH regulation system: So you should just be able to write the value you want to set. And you should be able to read it as a sensor.
The value set in this register is multiplied by 100. This means that if we want to set
a value of 7.0, the numerical content that we must write in this register is 700.
This register must be always lower than MBF_PAR_PH1.
 To make the modification of this register persistent, execute the EEPROM
storage procedure described in global register MBF_SAVE_TO_EEPROM.

NOTE: “The value set in this register is multiplied by 100. This means that if we want to set a value of 7, the numerical content that we must write in this register is 700” I think there may be a typo here: So register is multiplied by 100 may be register is divided by 100? But that needs to be clarified?

This register contains the status of each and every one of the configurable relays: This register is read only I imagine and should be setup as a sensor. Extracting the value of the individual relays in individual sensors is something I am not too sure about but we should be able to figure that out. So you should see 0000000 if all relays are ‘off’ and 1111111 if they are all ‘on’.

Lets stop there and await your reply

My way of particular bits reading:

  - platform: modbus
    registers:
    - name: MBF_PAR_FILTRATION_STATE
      hub: bazen
      slave: 1
      register: 1057
      register_type: holding
      data_type: uint
    - name: MBF_RELAY_STATE
      hub: bazen
      slave: 1
      register: 270
      register_type: holding
      data_type: uint

  - platform: template
    sensors:
      stav_ph_1:
        friendly_name: "stav ph 1"
        value_template: "{{ states('sensor.MBF_PH_STATUS')|int // 1 % 2 * 1 }}"
      stav_ph_2:
        friendly_name: "stav ph 2"
        value_template: "{{ states('sensor.MBF_PH_STATUS')|int // 2 % 2 * 2}}"
      stav_ph_3:
        friendly_name: "stav ph 3"
        value_template: "{{ states('sensor.MBF_PH_STATUS')|int // 4 % 2 * 4}}"
      ph1_ph2:
        value_template: "{{ states('sensor.stav_ph_1')|int + states('sensor.stav_ph_2')|int + states('sensor.stav_ph_3')|int }}"
      stav_ph:
        friendly_name: "Stav ph"
        value_template: >-
          {% if is_state('sensor.ph1_ph2', '0' ) %}
              OK
          {% elif is_state('sensor.ph1_ph2', '1' ) %}
              vysoké
          {% elif is_state('sensor.ph1_ph2', '2' ) %}
              nízké
          {% elif is_state('sensor.ph1_ph2', '3' ) %}
              AL3
          {% elif is_state('sensor.ph1_ph2', '4' ) %}
              vyšší
          {% elif is_state('sensor.ph1_ph2', '5' ) %}
              nižší
           {% else %}
              ???
          {% endif %}

      peristaltika:
        friendly_name: "Peristaltika"
        value_template: "{{ states('sensor.MBF_RELAY_STATE')|int // 1 % 2 == 1}}"
      filtrace:
        friendly_name: "Filtrace"
        value_template: "{{ states('sensor.MBF_PAR_FILTRATION_STATE')|int == 1 }}"
      ohrev:
        friendly_name: "Ohrev"
        value_template: "{{ states('sensor.MBF_RELAY_STATE')|int // 64 % 2 == 1 }}"

Reading data (pH, temperature):

  - platform: modbus
    registers:
    - name: MBF_MEASURE_PH 
      hub: bazen
      slave: 1
      register: 258
      register_type: holding
      data_type: uint
      scale: 0.01
      precision: 1
    - name: MBF_MEASURE_TEMPERATURE
      hub: bazen
      slave: 1
      register: 262
      register_type: holding
      data_type: uint
      unit_of_measurement: °C
      scale: 0.1
      precision: 1


@wellsy

At the moment my Hidrolife works in automated mode (heat) where it is possible to set up via cloud or device touch screen timers, target temperature, target pH, turn on/off light. Heating, pH control and chlorine generator are automated (inner logic)
In this mode MODBUS usage is a bit more complicated due to relations in the inner logic so I do not want it.
My target is:
manual mode of Hidrolife use its automated pH control and chlorine generator while having ability to switch on/off filtration, heater, lights and temperature by Hassio via MODBUS and use Hassio timers (to set up those in Hidrolife through MODBUS is complicated)
Temperature is changed via register MBF_PAR_HEATING_TEMP
All needed relays (heater, light, countercurrent) are controlled via particular bits in register MBF_RELAY_STATE except filtration controlled by MBF_PAR_FILT_MANUAL_STATE

So I could have better control over operational(inner) logic :slight_smile:

I see this device as being very much similar to a PLC with some limitations.
That is: it has its inbuilt logic and is designed to function ‘safely’ as a standalone controller. It seems to me the main limitation is you are stuck with the inbuilt program logic.
I would hesitate to aspire to bring HA into that logic. Its pretty clear from what the “Modbus-registers.pdf” tells me that they don’t really want you to mess around with quite a few things. I would say its a good idea to heed those warnings and use HA as a substitute for the ‘cloud’ IE: as a means to monitor it and change user configurable settings. The logic part…leave that to your controller.

If it were possible to open up and edit the internal program (as you can in a PLC) then by all means feel free to look at logic but in this device that seems as though that will not be possible.

Just my 2 cents.

So it looks you have reading sensors sorted what about setting up switches (and writing them ‘MBF_SAVE_TO_EEPROM’? Do you have that working?

Reading binary sensors working?

Binary sensors are up and running as well.
Final part with switches and other writes will start this weekend if I have time.

1 Like