Modbus bitmasks (decimal values) write

Hi. How to implement registers like that in esphome with modbus controller? I would to read and write registers like 0x0032 and 0x0033.


Read decimal values in read registers is easy but how to write them?

Example on this page may help: Modbus Controller — ESPHome

And the signature for create_write_single_command

Hi guys, I also encounter the same problem, Did you solve it?

Yes. Check my yaml for sprsun heat pump.

Do you have some more info how to connect to the sprsun heatpump?
Thanks

What model? Carel or elchico motherboard? It’s modbus TCP over elfin gateway or modbus rtu over esp.

I’m running mine of an esp32, and i’m able to get most to work, but i’m unable to get the on/off of the heat pump part to work, it sends the signal but after 10 sec it flip to on again by itself. is there a part that i’m missing?

You are using my yaml? Is heat pump response to on/off switch? I haven’t tested it yet.

Try to delete skip_updates variable from number component. Line number 1804. On/off switch reads state of the heat pump from number component.

Yes i use your Yaml, and a big ‘Thank You’ from me.
I will try to do that.

Let me know if this problem still occurs.

it shuts off, and all sensors goes dead (off) then after 30 sec it turns on by itself(homeassistant still shows off) and what looks like reset/change some af the settings like P01, P02, P03, P04 and P05. (P04 goes from 42 to 50.)
I have to say that i do have automations running changing the value of P01, P02, P03, P04 and P05 according to outside temperature, just like Eco mode.

So sending on/off command resets heat pump to factory default?

Sorry, I need to rewrite code… Please reset your heat pump to factory default.

I dont know if it reset it, all i can see is that it change the values of P01, P02, P03, P04 and P05 when it turns on again (by itself), but i cant see anything else changes, so it could be ok, and the problem is something else.
Does it work on Your side. if it do, the problem could be on my side.

I’m waiting to install my heat pump, so I haven’t tested it. I will write on/off code with select component and we will see if that works better.

I changed from switch to select component for parameter marker definition (on/off switch), check my pastebin and try it.

Its working now with the select insted of switch, and i’m testing other functions now.
I can not test all of it as i dont want to adjust all of the parameteres on the heatpump as i will proberly brake it. But i will test all of the normal settings, and give You feedback.

Thanks You for all of Your hard work…

1 Like
  1. on_off is working, no errors or reset
  2. Antilegionella is not starting/working
  3. Timeband/slot i have not tested it as i dont use it
  4. F56 Heat pump model - not working, it returns to blank (nothing selected)
  5. in eco mode, E01 Economic heat ambi and E02 Economic heat ambi, when set to minus 4 (-4) and minus 12 (-12) some times after a restart of esp the number is 65536 insted of -12, when i manually set it to -12 it stays there, it only happens to minus values.

I’m testing this from gpt4

  • platform: modbus_controller
    use_write_multiple: true
    modbus_controller_id: ${modbus_controller_id}
    id: sprsun_E01_Economic_heat_ambi_1
    name: “E01 Economic heat ambi 1”
    unit_of_measurement: “C”
    address: 0x0169
    step: 0.5
    min_value: -30
    max_value: 50
    value_type: U_WORD
    lambda: |-
    if (x > 32767) {
    return x - 65536;
    } else {
    return x;
    }
    write_lambda: |-
    if (x < 0) {
    return x + 65536;
    } else {
    return x;
    }
  1. Check your code
sensor:
  - platform: modbus_controller
    modbus_controller_id: sprsun_pc
    id: control_mark_2_raw
    register_type: holding
    address: 0x0034
    value_type: U_WORD
select:
  - platform: modbus_controller
    use_write_multiple: true
    modbus_controller_id: sprsun_pc
    name: "Antilegionella Enable 0-Unuse, 1-Use #bit add: 0x0340"
    id: antilegionella_enable
    address: 0x0034
    entity_category: config
    value_type: U_WORD
    optionsmap:
      "UNUSE": 0
      "USE": 1
    lambda: |-
      //ESP_LOGE("main","Modbus Number incoming value = %d",x);
      //ESP_LOGE("main","Modbus eval value = %d",(x & 0x0001));
      if ((x & 0x0001) == 0)
        return  std::string("UNUSE");
      if ((x & 0x0001) == 1)
        return  std::string("USE");
      return {};
    write_lambda: |-
      //ESP_LOGE("main","Modbus write gets = %d",value);
      uint16_t unmodified =  id(control_mark_2_raw).state;
      //ESP_LOGE("main","Modbus write unmodified = %d", unmodified);
      uint16_t modified = ((unmodified & ~0x0001) | value);
      //ESP_LOGE("main","Modbus write to write = %d", modified);
      return modified;
  1. Change value_type to S_WORD. This applies to any sensor with a negative value.

Check my newest pastebin code.

Hi.
@blackscreener
What model of SPRSun do you use?
What specific modbus controller model should I use to make this work for me?
Jarek

Hi, very interesting code, any tips how to turn it from select to switch type?
It’s more preferable to use on/off switch for example in thermostat…
cheers, marekorok