Adding a template to my Modbus.yaml file

Hello, I’m new to homeassitant and YAML. I have read so many articles and gone through so much documentation but I cannot find a way to add a template to my modbus.yaml file correctly. Im not adding this to my configuration.yaml, but to my actual modbus.yaml file. All the examples Ive seen have shown it in the config.yaml file, thats not what Im looking for.

My goal is to simply add a template to make data from a modbus door sensor say open if its 0, and closed if its 1. Thats It. Here is that config file with just one sensor to make it easier to read. Also, I am reading all my sensor data without issues just FYI.

- name: "Gateway"
  type: tcp
  host: xx.xx.xx.xx
  port: 502
  sensors:
    - name: "DOOR 4"
      scan_interval: 5
      slave: 1
      address: xxx

Here is my template im working with if that matters {{ ‘Closed’ if is_state(‘sensor.door_4’, ‘1’) else ‘Open’ }}"

I have tried many different ways but could someone please tell me the correct way to add this template to my modbus.yaml file.

Thanks!

no help, just saying that I struggle with the same issue. I ended up making additional entries, the one from Modbus and, building on it, a templated one

Could you post your configs please, I can learn from hem.

if it helps, happily

in modbus.yaml

 - name: "kermi"
   close_comm_on_error: true
   delay: 5
   timeout: 5
   type: tcp
   host: 192.168.0.11
   port: 8899
   sensors: 
     - {name: waterhot.temperature_modbus , device_class: temperature ,  unit_of_measurement: °C , data_type: int16 ,   input_type: holding   ,   swap: none   ,   slave: 1  ,  address: 1500  ,scan_interval: 60}   
     - {name: heatpump.temperature_modbus , device_class: temperature ,  unit_of_measurement: °C , data_type: int16 ,   input_type: holding   ,   swap: none   ,   slave: 1  ,  address: 1502  ,scan_interval: 60}   
     - {name: heatpump.vorlauf_modbus     , device_class: temperature ,  unit_of_measurement: °C , data_type: int16 ,   input_type: holding   ,   swap: none   ,   slave: 1  ,  address: 1501  ,scan_interval: 60}   
     - {name: heatpump.status                                                                    , data_type: int16 ,   input_type: holding   ,   swap: none   ,   slave: 1  ,  address: 6602  ,scan_interval: 20}   

in template

- sensors:
  - name: "heatpump temperature"
    unit_of_measurement: "°C"
    device_class: "temperature"
    state_class: "measurement"    
    state: >
      {{ states('sensor.heatpump_temperature_modbus') | float / 10 }} 
1 Like

@brun059 did you integrate a kermi heat pump into ha? How?

yes, I did, as per above (give or take the swap parameter)
I installed a cheap Modbus to TCP device from Aliexpress to read Kermi:
Search in Aliexpress.com for Serial Port RS485 to Ethernet Converter IOT Device Server Protoss-PE11 (it is about USD 15)

I configured as below and defined the modbus.yml as per above post (w/o swap parameter, this causes and error from 2024.1)

good luck