Reuse sensor value result in command_line - Variable

Hi,

I am looking for a way to store the output of externalip (see below) in a variable I can reuse in the below command line to exchange the dynamic external ip with what is currently hardcoded as 192.168.178.39.

Or even better to somehow use externalip as a variable in command:

Is there an easy solution for this?

Thanks,
Thomas

  - platform: dnsip
    name: externalip
    
  - platform: command_line
    name: linxdot_portcheck
    command: /bin/bash -c "(echo > /dev/tcp/192.168.178.39/44158) > /dev/null 2>&1 && echo ON || echo OFF"
    value_template: '{{ value }}'

Well, you have a sensor.externalip

You can do

    command: /bin/bash -c "(echo > /dev/tcp/{{ states('sensor.externalip') }}/44158) > /dev/null 2>&1 && echo ON || echo OFF"

1 Like