Hi,
We have a console that we can remotely telnet into and issue a command which provides the following data, is it possible to get this data into HA?
NAME
STREET ADDRESS
CITY STATE ZIP
PHONE NUMBER
AUG 20, 2020 9:43 PM
# NAME UNITS MEASURE DIF TEMP
1 READING1 2220 28.59 0.0 75.8
2 READING2 1260 18.94 0.0 77.7
3 READING3 1406 20.48 0.0 79.7
Hey @nickrout, no login, the flow is as follows in the command window.
telnet ip-address port#
Once connected, you would press ctrl & a together, release, then type 200, which populates the info in OP, and no, the server does not disconnect after providing the data.
I have to say that is an awful system to automate! Before I get into it further, are you sure there is no better system available? Like a rest sensor or something?
If you can do it in Python, then you can use telnetlib. The following is what I use to login to a router and get some data. By no means saying its well written, but it does work
I run it via cron periodically, and the results are output in JSON, which I decode in HA to create sensors. I am sure you could tailor it to achieve what you do above.
OK so you have a script that gets the text that the telnet generates. Lets call that text file scirpttest.
I assume that there are always the same line lengths, ie the data you want starts at byte 32 and finishes on 35.
grep searches a file and outputs the line that contains the text searched for.
cut finds characters from that line. In this case by bytecount from the start of the line.
grep READING1 scripttest
outputs
1 READING1 1578 22.25 0.0 78.5 4422
After cut is applied
grep READING1 scripttest|cut -b 32-35
outputs
1578
So your commandline sensor
sensor:
- platform: command_line
command: "grep READING1 scripttest|cut -b 32-35"
unit_of_measurement: "gal"
name: Reading1 Sensor
upload_interval: #this will depend how often you want it to update