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

This is the Yaml which links the input_select to the heatpump via modbus

alias: Energy State
description: ""
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": 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)  }}"

Hello @doezel
I did SW1 dip1 : ON
I connect Modbus cables A and B cable. And From screen I change Modbus Address 01
But when Im trying to connect I get Timeout error. What can be problem ?
I need to connect from C# app and read error codes or change operation modes.

You also have to set SW1 dip2 to ON (Unified open protocol).

Regarding an earlier question why the ETH to RS232/RS485 of Waveshare instead only RS485. That one has a modbus gateway function that translates between modbus RTU (RS485) and modbus TCP (ETH). Waveshare has multiple options with and without a modus gateway function. There is a table on this site showing which types are have a gateway function:

https://www.waveshare.com/product/iot-communication/wired-comm-converter/ethernet-to-rs232-rs485/rs232-485-to-eth.htm

Without a gateway the translation between ETH and RS485 is done transparently and that will not work directly. The frames of modbus TCP are slightly different from RTU. Note that modbus ascii is also different. The Therma V supports RTU.

Set on the wavesurf
ETH as TCP server and set the port to 502
RS485 to 9600baud stopbits:1 parity:none

1 Like

I tried this implementation.

- 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)  }}'

It works flawlessly. The only thing that needs attention is that the input_select options contain the state number in their names. And that in the last line of the yaml

value: '{{ trigger.to_state.state[x] | int(0)  }}'

x is replaced with the character position of the state number in the input select options.

So is the option reeds something like
- "0 - Power saving state not used"
x is 0 and when it reads
- " 0 - Power saving state not used"
x is 1.

1 Like

Hey!

I’ve looked into using the “energy state input”
Set it (holding register adr 9) to 1, seemed not to have an impact.
Is any other setting needed on the system?
The value seems to have been set, but the pump just seems to run?

Do you also see the status change on your display of the LG?

not that i can see. also no idea if this is an option i don’t have or something that needs to be activated or so. only thing i’m sure about is that it keeps the value when i set it

Hello!

I have ventilation and I also wanted to control and receive states. I did the automation as in the example, but I only get the status; when I select a mode, nothing happens. here is my config: Mode control register - 4

input_select:
  komfovent_set_mode:
   name: "Komfovent Set Mode" 
   options:
     - Minimum  
     - Away
     - Home
     - Boost

 - alias: Komfovent Set Mode
    description: 'Set the mode (app or web)'
    trigger:
      - platform: state
        entity_id: sensor.komfovent_mode_num
        id: input
        to: null
      - platform: state
        entity_id: input_select.komfovent_set_mode
        id: select
        to: null
    condition: []
    action:
    - choose:
      - conditions:
        - condition: trigger
          id: input
        sequence:
        - variables: 
            values:
              '1': Minimun
              '2': Away
              '3': Home
              '4': Boost
                
        - service: input_select.select_option
          target:
            entity_id: input_select.komfovent_set_mode
          data:
            option: '{{ values.get(trigger.to_state.state) }}'
      - conditions:
        - condition: trigger
          id: select
        sequence:
        - service: modbus.write_register
          data:
            address: 4
            slave: 1
            hub: "Komfovent"
            value: '{{ trigger.to_state.state[0] | int(0)  }}'
    mode: single

When selecting a mode, automation is executed, but the status is not a number but a text. Could this be the reason or am I doing something wrong?