Help with sensor template.. Reading text string for PDU

Would love some help with reading the status of my Synaccess PDU outlets. I have been able to control the switches, but struggling with reading the status.

Here is the control portion

- platform: command_line
  switches:
    office_np05_pdu_outlet1:
      friendly_name: NP05 Outlet 1
      command_on: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%201%201'
      command_off: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%201%200'
      unique_id: np05_0c73ebb0a1ae_01

    office_np05_pdu_outlet2:
      friendly_name: NP05 Outlet 2
      command_on: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%202%201'
      command_off: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%202%200'
      unique_id: np05_0c73ebb0a1ae_02

    office_np05_pdu_outlet3:
      friendly_name: NP05 Outlet 3
      command_on: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%203%201'
      command_off: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%203%200'
      unique_id: np05_0c73ebb0a1ae_03

    office_np05_pdu_outlet4:
      friendly_name: Airmotiv Speakers
      command_on: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%204%201'
      command_off: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%204%200'
      unique_id: np05_0c73ebb0a1ae_04

    office_np05_pdu_outlet5:
      friendly_name: Office Monitors
      command_on: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%205%201'
      command_off: curl -X POST --user "user:password" 'http://192.168.0.100/cmd.cgi?$A3%205%200'
      unique_id: np05_0c73ebb0a1ae_05

But how do I get the status portion, to get status it is one call that returns all outlets at once.

outlet_state: curl -X POST --user "user: password" 'http://192.168.0.100/cmd.cgi?$A5'

## RETURNED VALUE
$A0,11111 ##-> ALL ON
$A0,11110 ##-> ALL ON EXCEPT OUTLET 1, the order is reversed first digit is outlet 5, last is outlet 1

Any help would be appreciated… I did find a package integration that would possible work, but I’m running HAOS and I don’t think I can easily integrate it with venv, so creating my own interface seems like a less fraught task.

Thanks in advance!

Changed the title to see if someone might take a peek and provide some feedback. Just need to figure out how to read a text string into a sensor based on the location of a 1 or 0 in the string response from the curl call. See above.

Use the Command-line Sensor integration.

Taras… That was my intent, but I don’t have a clue of HOW to use it to parse the data. I have made the call and got the data returned, but how do I parse the location of the ‘0’ in the returned string to determine if an outlet is on or off. That is the question.

outlet_state: curl -X POST --user "user: password" 'http://192.168.0.100/cmd.cgi?$A5'

## RETURNED VALUE
$A0,11111 ##-> ALL ON
$A0,11110 ##-> ALL ON EXCEPT OUTLET 1, the order is reversed first digit is outlet 5, last is outlet 1

Using value_template. The question is: How do you want a single Command-line Sensor to report the states of the five outlets?

Or do you want to create five Command-line Sensors, each one responsible for reporting the state of one of the five outlets?


EDIT

Example of a template that can report the current state of outlet 1 (the last digit in the received value) as either on or off.

{{ iif(value[-1]|bool, 'on', 'off')  }}

This would be for outlet 5 (first digit in the received value).

{{ iif(value[-5]|bool, 'on', 'off')  }}

Taras

Thanks… Getting somewhere… I was hoping to build it into the actual switch for command_state to make it poll correctly on a YAML reset or HA restart.


- platform: command_line
  switches:
    office_np05_pdu_outlet1:
      friendly_name: NP05 Outlet 1
      command_on: curl -X POST --user "user:pw" 'http://192.168.1.100/cmd.cgi?$A3%201%201'
      command_off: curl -X POST --user "user:pw" 'http://192.168.1.100/cmd.cgi?$A3%201%200'
      command_state: curl -X POST --user "user:pw" 'http://192.168.1.100/cmd.cgi?$A5'
      value_template: "{{ iif('$A5,11110'[-1]|bool, 'on', 'off')  }}"
      unique_id: np05_00000000000_01

According to the documentation for Command line Switch, the value_template should report true/false to indicate on/off. Try it with the following template for Outlet 1.

  switches:
    office_np05_pdu_outlet1:
      friendly_name: NP05 Outlet 1
      command_on: curl -X POST --user "user:pw" 'http://192.168.1.100/cmd.cgi?$A3%201%201'
      command_off: curl -X POST --user "user:pw" 'http://192.168.1.100/cmd.cgi?$A3%201%200'
      command_state: curl -X POST --user "user:pw" 'http://192.168.1.100/cmd.cgi?$A5'
      value_template: "{{ value[-1] | bool }}"
      unique_id: np05_00000000000_01
1 Like

Taras

Looks like it is working. Does take about 30 secs to update after a restart/reload, but I think that is the expected polling interval. Thanks a ton!

1 Like