SNMP based command line switch

I have an APC PDU in my garage - where I keep my Home Lab setup. Plugged in to socket 1 is the garage light.

I can run the following commands as the homeassistant user and they work

Turn on the light
/usr/bin/snmpset -v 1 -c private pdu2.23wwc.org 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.1 integer 1

Turn off the light
/usr/bin/snmpset -v 1 -c private pdu2.23wwc.org 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.1 integer 2

Get the status - returns 1 or 2
/usr/bin/snmpget -Oqv -v 1 -c public pdu2.23wwc.org 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.1

So I put this in as a switch configuration.

   - platform: command_line
  switches:
    garage_light:
      command_on: "/usr/bin/snmpset -v 1 -c private pdu2.23wwc.org 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.1 integer 1"
      command_off: "/usr/bin/snmpset -v 1 -c private pdu2.23wwc.org 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.1 integer 2"
      command_state: "/usr/bin/snmpget -Oqv -v 1 -c public pdu2.23wwc.org 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.1"
      value_template: '{{ return_value == "1" }}'
      friendly_name: Garage Light

The switch appears in the HA interface but it doesn’t work. If I click the switch it slides over but then slides back after a few seconds. Also, if I turn the light on from the command line the switch in the interface still appears off.

This would imply that none of these commands are working.

I’ve found loads of examples where people’s command_on|off|status are curl commands but none using SNMP.

Can anyone see what I’m missing?

Thanks

Steve

2 Likes

Fixed it. Although the example says

value_template: '{{ return_value == "1" }}'

It works if I change it to

value_template: '{{ value == "1" }}'
2 Likes