How to link an input select list to/from a modbus list of integers

Hi,

i have a heatpump (LG Therma V) which I connect to via the Modbus integation (modbusTCP).
The most parameters I can read are temperature or basic on/off switches.
But some parameters are a list of possible values which are stored as integers; like this:

This is how I read that parameter (now)

      - name: energy_state_input_holding
        scan_interval: 5
        address: 9
        slave: 1
        input_type: holding

What I would like to achieve is that I can have a dropdown/radiobutton list in my dashboard where I can read/update that energy state (as well as all other options of my heat-pump).

I have made a Helper with all the status. What I need is a starting point on how I can link those states to the integer value I can read/write from and to the modbus. In C# I would have made an enum and a databinding between the parameter and that enum.

I’ve never used Modbus, so this might not be 100% what you need… but to link your helper to the value of the sensor you need an automation (or you could ditch the helper and use a template select which is basically a helper and automation rolled into one)

trigger:
  - platform: state
    entity_id: sensor.energy_state_input_holding
    id: input
    to: null
  - platform: state
    entity_id: input_select.wp_energy_state
    id: select
    to: null
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: input
        sequence:
          - variables: 
              values:
                '0': "0. Not Use"
                '1': FILL_US_IN
                '2':
                '3':
                '4':
                '5':
                '6':
                '7':
                '8': 
          - service: input_select.select_option
            target:
              entity_id: input_select.wp_energy_state
            data:
              option: '{{ values.get(trigger.to_state.state) }}'
      - conditions:
          - condition: trigger
            id: 
        sequence:
          - service: modbus.write_register
            data:
              address: 40010
              unit: 9
              hub: <YOUR_HUB_NAME>
              value: '{{ trigger.to_state.state[0] | int(0)  }}'
mode: single
1 Like

Thanks! I’ll give it a try.

It’s working partially;

when I update the “sensor.energy_state_input_holding” via a switch, the value is parsed fine to the “input_select.wp_energy_state”

    switches:
      - name: energy_state_input_switch
        scan_interval: 5
        address: 9
        slave: 1
        write_type: holding


But when I try to adjust the input_select itself; the value isn’t written to the modbus.
When I alter the select to option 4:

I get this error:

But the modbus write command shows the correct parameter:

Any idea how to debug this furter?

This is how the automation is configured now:

- id: map energy state
  alias: Energy State
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.energy_state_input_holding
    id: input
    to:
  - platform: state
    entity_id:
    - input_select.wp_energy_state
    id: select
    to:
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: input
      sequence:
      - variables:
          values:
            '0': 0. Not Use
            '1': 1. Forced Off
            '2': 2.Normal Operation
            '3': 3. On-recommandation
            '4': 4. On-command
            '5': 5. On-command step 2
            '6': 6. On-recommendation Step 1
            '7': 7. Energy Saving mode
            '8': 8. Super Energy Saving mode
      - service: input_select.select_option
        target:
          entity_id: input_select.wp_energy_state
        data:
          option: '{{ values.get(trigger.to_state.state) }}'
    - conditions:
      - condition: trigger
        id: select
      sequence:
      - service: modbus.write_register
        data:
          address: 9
          slave: 1
          hub: lg_modbus
          value: '{{ trigger.to_state.state[0] | int(0)  }}'
          mode: single
          write_type: holding

OH! the parameters of the “modbus.write_register” should have been a “data_template” instead of just “data”

Now It’s working!

and this is the code in automations.yaml:

- id: map energy state
  alias: Energy State
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.energy_state_input_holding
    id: input
    to:
  - platform: state
    entity_id:
    - input_select.wp_energy_state
    id: select
    to:
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: input
      sequence:
      - variables:
          values:
            '0': 0. Not Use
            '1': 1. Forced Off
            '2': 2.Normal Operation
            '3': 3. On-recommandation
            '4': 4. On-command
            '5': 5. On-command step 2
            '6': 6. On-recommendation Step 1
            '7': 7. Energy Saving mode
            '8': 8. Super Energy Saving mode
      - service: input_select.select_option
        target:
          entity_id: input_select.wp_energy_state
        data:
          option: '{{ values.get(trigger.to_state.state) }}'
    - conditions:
      - condition: trigger
        id: select
      sequence:
      - service: modbus.write_register
        data_template:
          address: 9
          slave: 1
          hub: lg_modbus
          value: '{{ trigger.to_state.state[0] | int(0)  }}'

Still a question remains; is this the best way to do this? As I have to store the mapping in both an input_select and in this automation?

1 Like

Since the sensor values are well-matched with the array index, you should be able to eliminate the mapping by using the value from the sensor to pull the value of the select’s option… (untested)

- id: map energy state
  alias: Energy State
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.energy_state_input_holding
    id: input
    to:
  - platform: state
    entity_id:
    - input_select.wp_energy_state
    id: select
    to:
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: input
      sequence:
      - variables:
          index: '{{ trigger.to_state.state | int(0) }}'
      - service: input_select.select_option
        data:
          option: '{{ state_attr("input_select.wp_energy_state", "options")[ index ] }}'
        target: 
          entity_id: input_select.wp_energy_state
    - conditions:
      - condition: trigger
        id: select
      sequence:
      - service: modbus.write_register
        data_template:
          address: 9
          slave: 1
          hub: lg_modbus
          value: '{{ trigger.to_state.state[0] | int(0)  }}'
1 Like

Hi @doezel,
can you please tell me, how you configure your heatpump to activate the modbus. I use a LG Therma V Monoblock HM091MR.U44 and looking for the right configuration.
And what kind of modbusTCP device do you use?
Claus

Hi Claus,

Do you have the installation manual? You have to setup the Therma V as an Modbus Slave, not master. And Address 1.

This is the device I use: https://www.waveshare.com/rs232-485-to-eth-for-eu.htm

Hi doesel,

I have the same heatpump as Claus. And at the moment I’m trying to decide if I go with the modbus approach ou wifi via LG thinq.

The thing is, never used neither of them and for both I have to adquire extra hardware. Could you point me in the right direction to learn how to use modbus with HA? I’ve seen a lot of diferent approaches, but since you have one that works I was hoping your guidance would be the most wiser.

Tks in advance

Hi rijolo,

The standard Wifi solution of LG is VERY limited. It shows hardly any sensors and can’t control the 2nd circuit if you have that connected.

The modbus solution is a lot cheaper and gives access to ALL parameters that are in our ThermaV heatpump. But this solution isn’t really plug-and-play.

Hope this helps.

Is there any tutorial you recommend? Can’t find any for the therma V…

I haven’t found one. You use setup the Home Assistant modbus integration to get all parameters you need. Those parameters are in the LG integration manual.

And then you automate and add graphics for all those parameters in Home Assistant.

1 Like

Oh ok,

Yes I belive the instalation manual has a lot of info about the modbus connection, going to dig that up.

Hardware wise, you used the rs232/rs485 in opposition to just the rs485 for any reason?
In my local Amazon the rs485 is almost half the price of the rs232/rs485.

Hi Doezel,

can you please explain on which connector of the heat pump you wired the rs485 converter ?

Al

Ok I think I found it :slight_smile:
It’s the “third party controller” marked terminal block on external unit (either on split or monobloc model).
This can be found on installation manual.

Hi Doezel.
If someone asks you to explain on which connector you wired your convertor, why don’t you give an answer? No one on the Internet explains how it’s connected .

It should be something like
"There is a terminalblock in the heat pump with a text “Aansturing voor besturing van derde”. In my HP it’s terminalblock 3. It has two connections numbered 26 and 27. The text is A for the 26 and B for the 27.
The convertor itself has also terminals with a text A+ and B- and a ground. Just connect
terminal 26 (A) of the HP with terminal A+ of the convertor and
terminal 27 (B) of the HP with terminal B- of the convertor.
You do not need to connect the ground.

Hello,
I am also trying to communicate with the Therma V with modbus, however without success so far.
Did you have to change some DIP switch settings (Slave mode ?) or change some parameters on the remote control interface ?
I’m just trying with an RS485 / USB interface and a modbus master software before putting HA in the loop.

thanks

Yeah set dip 1 in option switch 1 to “ON”.
Further LG peculiarities include mapping holding registers to input register space, so in hass you have to switch input_types to get correct values.

p.s. There are also a lot of registers that can be read outside the documented addresses.

p.p.s. I found an up to date installation manual that had info on R32 version on LG UK site.

p.p.p.s Oh I can’t remember if dip 2 had to be on as well that is the protocol dip. I sat in the cold with my laptop and went through the options, so as it started working, I stopped looking.

Hi @doezel,

Could you please provide the code of the Automations.yaml the way how to add this to an dashboard, to switch the energy state?

many thanks!