How to convert two numeric values from file to binary sensor state?

Hi,
I need to create binary_sensor, that reads input from single line text-file. I think templates are tool to use, but so far, haven’t been able to create suitable valuable template. The code I have in binarysensor.yaml:

- platform: command_line
  name: Oumanltptila
  command: cut -b 17 /config/oumanltp.txt

Cut -b 17 extracts value from byte 17 in text file, this can beeither 0 or 1. Text-file is created by another system command. This part works, tested on command shell and I use similar code to get temperature data. This passes also all syntax-checking, but it causes state to be undefined.

What kind of template configuration I need to simply set binarysensor to true for value 1, and false for 0? Device tha outputs file is heating controller and its output is easiest to read from these files, its web-interface data is hard to extract, so no REST or SCRAPE.

Contents of text-file is:

result?S_135_85=1;

and result code is after = mark, 135_85 is static register number.

Did you try the payload options?

    payload_on: 1
    payload_off: 0

Thank you very much! This solved my problem completely and IMO, it’s more elegant solution than using template. I never thought this possibility before, that HA can make this kind of conversions.

This solution allows me to share how-to guide on using this particular heating controller (Ouman EH-800) with HA, it’s ver popular device in Finland, but no much information on using with HA.

1 Like