Addition of a E-meter 8870 USB current clamp

Hello,
I am trying to use this clamp with HA

USB E-meter 8870
Documentation


Report your problem

This is a USB connection that works in series like old USB modems…
On a Linux with picocom we get the clamp measurement.
picocom -b 19200 /dev/ttyACM0
then @ to read the value
5.2
5.4 at each @ on the keyboard.
I added this config

sensor:
  - platform: serial
    serial_port: /dev/ttyACM0
    name: UsbPower8870
    baudrate: 19200

But the entity remains empty. It is necessary to send the read request carried out by the @ command and there I will not be able to indicate this in the config.
The serial doc :
talks about template but not about placing a command.

If you had any info?
Maybe I’m not using the right method to integrate this material.

Thank you for your answers
Mr.B.

hello,
So i try with command_line…
in configuration.yaml

command_line:
  - sensor:
      name: UsbPowerMeter
      command: "python3 /root/homeassistant/current_clamp.py /dev/ttyACM0 19200 '@'" 
      unit_of_measurement: 'Amp'
      value_template: "{{ value }}"
      scan_interval: 
        seconds: 5

i try both,
in python

#!python3
import sys
import asyncio
import serial_asyncio_fast as serial_asyncio

async def main(port, baudrate, command):
    reader, writer = await serial_asyncio.open_serial_connection(url=port, baudrate=int(baudrate))
    writer.write((command + '\n').encode())
    line = await reader.readline()
    print(line.decode().strip())
    writer.close()
    await writer.wait_closed()

if len(sys.argv) != 4:
    print("Usage: python current_clamp.py <port> <baudrate> <command>")
    sys.exit(1)

port = sys.argv[1]
baudrate = sys.argv[2]
command = sys.argv[3]

asyncio.run(main(port, baudrate, command))
sys.exit(0)

[homeassistant.components.command_line.utils] Command failed (with return code 2): python3 /root/homeassistant/current_clamp.py /dev/ttyACM0 19200 ‹ @ ›

and with shell

#!/bin/zsh
/usr/bin/microcom -s 9600 /dev/ttyACM0 & pid=$! | true
sleep 2
echo '@' > /dev/ttyACM0
kill -2 $pid

[homeassistant.components.command_line.utils] Command failed (with return code 127): /root/homeassistant/current_clamp.sh

neither is working but in terminal both is working and give the current …

say if you have ideas …