How to get the shell command result?

I need to get the IP of the devices connected to my lan, so I installed nmap, and I get the list with sudo nmap -sn command. But I want to send the comand from home assistan, and get the resul. I know how to call it from an HA script, but no idea how to show the result…
Does anybody know it? Thanks

That will return the entire command output by default, which is likely in excess of the 255-character limit for a state. You could do something like:

    value_template: '{{ value.replace("\n","")|regex_findall("\.(\d+)Host is up")|join(",") }}'

which would give you a comma-separated list of final octets for hosts that are up, which should fit in 255 characters for fewer than 60 live hosts.

What are you trying to do with it?

1 Like

Just get a list of the devices connected to my lan… because my router is faulty, reset from time to time and change some of my devices IP… fixed IP are ignored…while I am waiting for my ISP solution , basically a new router replacement, I need to know the new IP to remotely…

It seems command line don’t work. I think this is because I run HA in a docker, and Nmap was installed from raspian os, outside the container… I run shell commands in this cases by ssh from HA, like
shell_command: IP:Scan: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /folder/id_rsaMYRASPBERRY sudo nmap -sn
This work for outside container commands, like open or close servers, or in this case, calling Nmap.
But I am nor sure how add the template to get the result of the command, where must I add the template in the script code:
` allias: IP scan

  • service: shell_command.ipscan
    data: {}
    mode: single `