Modbus platform template

Hi, I do not know how to proceed. Each try ends in an error like: platform is invalid in modbus configuration.
Here is my modbus yaml, the first lines of 242:

- name: nilan
  type: tcp
  host: 192.168.188.107
  port: 502
  sensors:
    - name: Nilan_operation_mode
      address: 5432
      slave: 1
      data_type: int16
      input_type: holding    
      unique_id: nilan operationsmodus
    - name: Luftfeuchtigkeit
      unique_id: nilan_humidity
    # Current humidity
      address: 4716
      unit_of_measurement: "%"
      slave: 1

The “nilan_operation_mode” presents five values 0 to 4. For all user this would be
easier to comprehend:

template:
      value_template: >
        {% if states('sensor.nilan_operation_mode') | int == 0 %}
          "Wert ist undefiniert"
        {% elif states('sensor.nilan_operation_mode') | int == 1 %}
          "kühlen"
        {% elif states('sensor.nilan_operation_mode') | int == 2 %}
          "heizen"
        {% elif states('sensor.nilan_operation_mode') | int == 3 %}
          "entfeuchten"
        {% elif states('sensor.nilan_operation_mode') | int == 4 %}
          "Wasser aufheizen"                
        {% else %}
          "Unbekannter Wert"
        {% endif %}

This does not work.

I have already tried

  • platform: template → mapping error
    platform: template → invalid configuration platform nor part of modbus …

I am mixed up with the position of sensors or sensor! There are a lot of opinions that there is only room for one sensors but where?
Before platform and after platform, HA ends always in configuration lets HA not start.
Both options ended up in a numerous shifting of code down the lines of template and then back shifting, so that it will at least work again.
Is there by the way a intelligent yaml editor which shifts the following code and vise versa?

Thanks for your responses.
Manfred

Hello,

not very clear how is your configuration.
I suppose you have split configuration so you include in your configuration.yaml for modbus via modbus: !include modbus.yaml , correct?

Then don’t you have a split configuration for templates? you included in configuration.yaml?
you included templates in the modbus.yaml?

I suggest you split the configuration for templates too.

So your configuration,yaml will look like:

template: !include templates.yaml
modbus: !include modbus.yaml

then in same folder you will have two files:

modbus.yaml

- name: nilan
  type: tcp
  host: 192.168.188.107
  port: 502
  sensors:
    - name: nilan_operation_mode
      address: 5432
      slave: 1
      data_type: int16
      input_type: holding    
      unique_id: nilanoperationsmodus
    - name: Luftfeuchtigkeit
      unique_id: nilan_humidity
    # Current humidity
      address: 4716
      unit_of_measurement: "%"
      slave: 1

no validation error in my test.

templates.yaml

- sensor:
    - name: "yournameforsensor"
      unique_id: auniqueid
      state: >
        {% set nilan = states("sensor.nilan_operation_mode") | float(0) %}
        {% if nilan | int == 0 %}
          "Wert ist undefiniert"
        {% elif nilan | int == 1 %}
          "kühlen"
        {% elif nilan | int == 2 %}
          "heizen"
        {% elif nilan | int == 3 %}
          "entfeuchten"
        {% elif nilan | int == 4 %}
          "Wasser aufheizen"                
        {% else %}
          "Unbekannter Wert"
        {% endif %}
      availability: >
        {{ states('sensor.nilan_operation_mode') | is_number }} 

this gives no validation error in my test


VSCode or Notepad++

Many Thanks.

The Idea for separating the template.yaml is very convenient.
There are no configuration errors. BUT.

The numbers from sensor.nilan_operation_mode will not change.
In the entities there is the new one from the template.yaml. But this entity says it does not exit.
Here are all yaml.files which should connect.

configuration.yaml


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Load dashboard Editor
config_editor:
# Load modbus
template: !include template.yaml
modbus: !include nilan_test_02.yaml
# Load multiscrape
multiscrape: !include bayrol.yaml
logger:
  default: info
  logs:
    homeassistant.components.modbus: debug

template.yaml

- sensor:
    - name: Template_sensor
      unique_id: TS01
      state: >
        {% set nilan = states("sensor.nilan_operation_mode") | float(0) %}
        {% if nilan | int == 0 %}
          "Wert ist undefiniert"
        {% elif nilan | int == 1 %}
          "kühlen"
        {% elif nilan | int == 2 %}
          "heizen"
        {% elif nilan | int == 3 %}
          "entfeuchten"
        {% elif nilan | int == 4 %}
          "Wasser aufheizen"                
        {% else %}
          "Unbekannter Wert"
        {% endif %}
      availability: >
        {{ states('sensor.nilan_operation_mode') | is_number }}

nilan_test_02.yaml

- name: nilan
  type: tcp
  host: 192.168.188.107
  port: 502
  sensors:
    - name: Nilan_operation_mode
      address: 5432
      slave: 1
      data_type: int16
      input_type: holding    
      unique_id: nilan_operation_mode
    - name: Luftfeuchtigkeit
      unique_id: nilan_humidity
    # Current humidity
      address: 4716
      unit_of_measurement: "%"
      slave: 1
    - name: Product type
      unique_id: CompactP
      address: 21680
      slave: 1
      unit_of_measurement: "hw"
    - name: Außentemperatur
      unique_id: Nilan_Temp_T1_Outdoor
      address: 5152
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Nilan_Temp_T2_Supply
      address: 5153
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Raumtemperatur
      unique_id: Nilan_Temp_T3_Extract
      address: 5154
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: "°C"
    - name: Nilan_Temp_T4_Discharge
      address: 5155
      data_type: int16
      scale: 0.1
      precision: 2
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Nilan_Temp_T5_Condenser
      address: 5156
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Nilan_Temp_T6_Evaporator
      address: 5157
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Nilan_Temp_T7_Inlet_air_after_reheating
      address: 5158
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Wassertemperatur oben
      unique_id: Nilan_Temp_T11_DHW_Top
      address: 5162
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Wassertemperatur unten
      unique_id: Nilan_Temp_T12_Bottom
      address: 5163
      data_type: int16
      scale: 0.1
      precision: 1
      input_type: holding
      slave: 1
      unit_of_measurement: °C
    - name: Nilan_filter_in_limit
      address: 1326
      slave: 1
      data_type: int16
      input_type: holding
    - name: Nilan_filter_out_limit
      address: 1327
      slave: 1
      data_type: int16
      input_type: holding
    - name: Nilan_filter_in_days
      address: 1328
      slave: 1
      data_type: int16
      input_type: holding
    - name: Nilan_filter_out_days
      address: 1329
      slave: 1
      data_type: int16
      input_type: holding
    - name: Nilan_compressor
      address: 4706
      slave: 1
      data_type: int16
      input_type: holding
      virtual_count: 6
    - name: Nilan_param_UserFanSpeed
      address: 4747
      slave: 1
      data_type: int16
      input_type: holding
      offset: -100
    - name: Nilan_param_pause_mode
      address: 4727
      slave: 1
      data_type: int16
      input_type: holding   
    - name: Nilan_extract_fan
      address: 4700
      slave: 1
      scale: 1
      data_type: int16
      input_type: holding
      unit_of_measurement: '%'
    - name: Nilan_supply_fan
      address: 4699
      slave: 1
      scale: 1
      data_type: int16
      input_type: holding
      unit_of_measurement: '%'
    - name: Nilan_deterioration_inlet_filter
      address: 4692
      slave: 1
      data_type: int16
      input_type: holding
      unit_of_measurement: "%"
    - name: Nilan_deterioration_outlet_filter
      address: 4693
      slave: 1
      data_type: int16
      input_type: holding
      unit_of_measurement: "%"        
    - name: Nilan_reheating_output
      address: 5374
      slave: 1
      scale: 1
      data_type: int16
      input_type: holding
      unit_of_measurement: '%'      
    - name: Nilan_allow_external_cooling
      address: 5375
      slave: 1
      scale: 1
      data_type: int16
      input_type: holding
      unit_of_measurement: '%' 
    - name: Nilan_4way_valve
      address: 4703
      slave: 1
      data_type: int16
      input_type: holding
    - name: Nilan_bypass1State
      address: 4704
      slave: 1
      data_type: int16
      input_type: holding
    - name: Nilan_outlet_filter_reset
      slave: 1
      address: 4757
      data_type: int16
      input_type: input  # oder "holding" je nach Gerät
      unique_id: outfilter_time_reset
          #count: 1
          # data_type: float16  # Datentyp für einen binären Sensor
          # value_template: "{{ value | int }}"
          # verify:
          #state_on: 1      # Wert für "ein"
          #state_off: 0     # Wert für "aus"
  climates:
    - name: Nilan_Temp_DHW_setpoint
      address: 5548
      target_temp_register: 5548
      slave: 1
      data_type: int16
      input_type: holding
      max_temp: 60
      precision: 1
      scale: 0.1
      temperature_unit: °C
    - name: Nilan_UserTemperature_setpoint
      address: 4746
      target_temp_register: 4746
      slave: 1
      data_type: int16
      input_type: holding
      max_temp: 33
      precision: 10
      scale: 0.1
      temperature_unit: °C
    - name: Nilan_Summer_Winter_Temp_setpoint
      address: 2406
      target_temp_register: 2406
      slave: 1
      data_type: int16
      input_type: holding
      max_temp: 15
      precision: 1
      scale: 0.1
      temperature_unit: °C
  binary_sensors:
    - name: Nilan_do1_compressor
      address: 5284
      input_type: holding
      slave: 1
    - name: Nilan_do2_dwh_heater
      address: 5285
      input_type: holding
      slave: 1
    - name: Nilan_dwh_heater_enabled
      address: 3938
      input_type: holding
      slave: 1

Hello,

Does the sensor exists among your entities?

Did you restart after making changes?

Now I have this.

How do I delete entities. I believe I could do this once.

And yes:

I have/had sensor.nilan_operation_mode.
I start always Home Assistant completely, not only the yaml configuration.

Hello,

It looks correct.
The sensor nr 6 is the one that exists correct?

To delete you can click on the line and then gear icon and delete.

Thanks again for your insight.

This is the sensor. But now in all codes the additional _6
Is missing, am I right?

Can I rename the sensor back to without the additional _6 ?

sensor.nilan_operation_mode_6

I renamed the sensor, restarted HA but the code doesn’t do what’s supposed to do.


Hello,

what should be the value of nilan_operation_mode?
As I can see now is 2 so the Template_sensor = “heizen”.
Not sure what is going wrong.

I suggest you to use the following tools while devellopping something like this.

Developper Tools > States
Developper Tolls > template

Developer tools - Home Assistant

This helps you to see what is happening and testing your code without restarting everytime.
In template section you can write down the code and see what are the results, also what are the errors with some kind of suggestion.

By the way what are you controlling a cooling / heating control?
My german is not that good :sweat_smile:

A Nilan is a Air 2 Air Heat Pump. It heats and occasionally cools and dehumidifies our passive house.

It seems to work. The hint is that the sensor of the template shows the words not the Nilan sensor.

So you see I am starting to make Home Assistant more personal.

Thanks for the tips. I will start to read into that.

Hello,

happy it worked.
I suggest you describe the solution or mark a solution so other can use this.