Modbus Integer Write Out

So filtration on/off works. ON as register write of value 1, OFF as write [0]. Yes, eachin different format.
Modbus switch works for ON only.
So far I do not use MBF_SAVE_TO_EEPROM, it saves automatically in 10 minutes interval.

1 Like

Can you post an example of your modbus switch config please

  - platform: modbus
    registers:
    - name: filtrace_mb   #  MBF_PAR_FILT_MANUAL_STATE
      hub: bazen
      slave: 1
      register: 1043
      command_on: 1
      command_off: 0

If that is not working just try this way.

  platform: modbus
  scan_interval: 10
  coils:
    - name: Switch1
      hub: hub1
      slave: 1
      coil: 13
    - name: Switch2
      hub: hub1
      slave: 2
      coil: 14

Have another read of the Modbus switch docs

It can be done both ways but I have found all my switches work configured like above…coils not registers and command not required. Worth trying I think?

Hm, if the address 1043 is not red as a coil (by modScan) it should not be used as the coil to control it. Or am I wrong?
I did a few more tests and now the modbus_write is standardized and working:

for off:

- address: 1043
  unit: 1
  value:  [0,0]
  hub: bazen

for on:

- address: 1043
  unit: 1
  value:  [1,0]
  hub: bazen

If that is working now then use that. Excellent news! FYI I read and write registers in the range 0-525 and 768-1599 as coils with HA on my PLC’s. It depends on your manufacturers implementation I believe?

I’ve tried to find coils in registers but w/o positive result.

Only one issue remains not solved, I am not able to control heater by the Hidrolife internal relay. I’ll try to ask guys who are implementing Hidrolife to Loxone how they did it.
By external relay it will be done in a minute but it won´t be neat and tidy :grin:
Great thank you for your advices.

In your working example above you are using the value: [1,0] for ON and the value: [0,0] for OFF

So I believe that is addressing bit ‘0’ and setting the value to ‘0’ or ‘1’ right?
What if you use the same format in your remaining “control heater by the Hidrolife internal relay”? Is it just bit ‘0’ as well or one of the multiple relay registers?

You are right, in this case it is addressing bit ‘0’ in the register vith only two values 1 and 0.
But in the case of register with multiple values ie 0-255 for 8 bit register and unsinged integer I am still not able to change one single particular bit.
Example:
I have register with values [0,1,0,0,0,1,0] (int value 34) and I need to chage it to [1,1,0,0,0,1,0] (int value 98)
If I write 98 - nothing, if [64,0] it changed bit 7 only, if [64,32,0] again bit 7 only if I use [64,32,0,0,0,2,0] nothing.
So multiple relay register (0x010E) at least in my case apparently requires other approach

Ok…how are you sending these writes for you multi relay register? An automation?

I dont understand why this won’t work then for bit ‘0’

- address: 270
  unit: 1
  value:  [1,0]
  hub: bazen

- address: 270
  unit: 1
  value:  [0,0]
  hub: bazen

and by extension for bit 6:

 - address: 270
   unit: 1
   value:  [1,6]
   hub: bazen
 
 - address: 270
   unit: 1
   value:  [0,6]
   hub: bazen

dev-services, write to a modbus holding register

@kajmaj Ok I have never used that…the standard modbus integrations just work for the PLC’s I have. Makes it pretty easy to setup thankfully.

I did two edits in my last post you may have answered before I edited and I didn’t notice your answer? Please take a look at the two ideas for addressing bits ‘0’ and ‘6’ above?

Tested both ways. Non of them works :frowning:
Address a bit in a correct way seems to be a big obstacle in my case.

1 Like

Bummer…and have you tried getting info here yet?

Have you also thought about how to get your present solution for switching to become a workable toggle switch? I know what you have devised is doing the job but its not yet a workable arrangement for a UI switch?

workable arrangement is done :laughing:

sensor:
- platform: template
  sensors:
    filtrace_mb_num:
      value_template: >
        {% if is_state('input_boolean.filtration', 'on') %} 1 {% else %} 0 {% endif %}
automation:
- alias: Zapnuti filtrace mb
  trigger:
    - platform: state
      entity_id: input_boolean.filtration
  condition: 
  - condition: state
    entity_id: input_boolean.bazen
    state: 'on' 
  action:
    service: modbus.write_register
    data:
      hub: bazen
      unit: 1
      address: 1043
    data_template:
      value: ["{{states('sensor.filtrace_mb_num') | int}}",0]

input_boolean.filtration will be controlled by automation fired by timer.

Rest of “writes” is a lot of more tricky and will require a bit more of tests and time.

1 Like

Nice job! Keen to see what else you come up with and know why it is “tricky”?

Tricky part was to verify writing to each of registers.
Wrong format caused bricked device several times, fortunately it was possible to solve by a service reset. But I was quite scared after it occured first time :rofl:

script:
  heating_mb_toggle:
    sequence:
    - service: modbus.write_register
      data:
        hub: bazen
        unit: 1
        address: 1152
        value: [16384]
    - service: modbus.write_register
      data:
         hub: bazen
         unit: 1
         address: 1241
      data_template:
        value: ["{{states('sensor.tepelne_cerpadlo_mb_num') | int}}"]
    - service: modbus.write_register
      data:
        hub: bazen
        unit: 1
        address: 752
        value: [1]
    - delay: 00:00:01
    - service: modbus.write_register
      data:
        hub: bazen
        unit: 1
        address: 757
        value: [1]
        
  filtration_mb_toggle:
    sequence:
    - service: modbus.write_register
      data:
        hub: bazen
        unit: 1
        address: 1041
        value: [0]
    - service: modbus.write_register
      data:
        hub: bazen
        unit: 1
        address: 1043
      data_template:
        value: ["{{states('sensor.filtrace_mb_num') | int}}"]
  run_a_cycle_mb:
    sequence:
      - wait_template: "{{ is_state('binary_sensor.filtrace', 'off') }}"
      - service: script.filtration_mb_toggle
      - wait_template: "{{ is_state('binary_sensor.filtrace', 'on') }}"
      - service: script.heating_mb_toggle
      - delay: 
           minutes: "{{states('sensor.delay_' + cycle + '_mb')}}"
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.filtrace_mb_auto
      - delay: 00:00:02
      - service: script.heating_mb_toggle
      - delay: 00:00:10
      - service: script.filtration_mb_toggle
1 Like

Great to hear your solution is complete. No more cloud just local control…well done!