Posting here to check if this is possible and also to document what I finally figured out after a lot of trial/error, since I couldn’t find much as I worked on this.
I have 2 Cisco PoE switches I use for my home network. I want to create switches in HA so I can control the PoE on each interface. I was able to create SNMP switches but they don’t self update so, if I change the setting on the switch itself, HA gets out of sync. I know I could ‘make’ this work but seems like REST is the better option.
SNMP Switches for PoE
For reference/documentation, here’s what worked in HA (it does take some configuration on the switch for SNMP permissions) :
- Cisco IOS Commands:
-
Create a view allowing access to SNMP
snmp-server view HomeAssistantView iso included -
Create an ACL to restrict access to SNMP
ip access-list standard 14
remark Allow SNMP from HomeAssistant and HomeAssistant Host
5 permit host 192.168.1.x log
10 permit host 192.168.1.x log
15 permit host 192.168.1.x log
50 deny any log
exit -
Create a group and associate it to the view and ACL
snmp-server group HomeAssistantGroup v3 auth read HomeAssistantView access 14
snmp-server group HomeAssistantGroup v3 auth write HomeAssistantView access 14 -
Create a user and add it to the group
snmp-server user HomeAssistantUser HomeAssistantGroup v3 auth sha priv aes 256
- Rest Config YAML (per port)
- platform: snmp
name: Cisco_Core1_Port01_PoE
host: !secret snmp3_coreswitch1_ip
version: "3"
username: !secret snmp3_user
auth_key: !secret snmp3_auth_key
auth_protocol: !secret snmp3_auth_protocol
priv_key: !secret snmp3_priv_key
priv_protocol: !secret snmp3_priv_protocol
baseoid: 1.3.6.1.2.1.105.1.1.1.3.1.1
payload_on: 1
payload_off: 2
- Secrets YAML
snmp3_coreswitch1_ip: 192.168.x.x
snmp3_user: HomeAssistantUser
snmp3_auth_key: <AuthPassword>
snmp3_auth_protocol: hmac-sha
snmp3_priv_key: <PrivPassword>
snmp3_priv_protocol: aes-cfb-256
Sorry, off topic, but didn’t want to start an entire new topic just to document that. Hopefully, it helps someone else in the future.
The actual point of this post…
Anyway, that worked but got out of sync so I figured RESTful switches made more sense.
So, I’m able to create a RESTful switch using the following (RESTCONF must be enabled on the switch and a Privilege 15 user credential must be specified below):
Note the last part of the URL, which is the interface - 1%2F0%2F1 = 1/0/1 . This must be updated on each line and match whatever Cisco reports the interface as.
- platform: rest
name: Cisco Core 1 - Port 01 - PoE
unique_id: Cisco_Core1_Port01_PoE
resource: https://192.168.1.x/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1%2F0%2F1
verify_ssl: false
method: patch
scan_interval: 180
timeout: 60
username: !secret cisco_rest_user
password: !secret cisco_rest_password
headers:
Content-Type: application/yang-data+json
Accept: application/yang-data+json
body_on: '{"Cisco-IOS-XE-native:GigabitEthernet":{"name":"1/0/1","Cisco-IOS-XE-power:power":{"inline":{"auto-choice":"","auto":""}}}}'
body_off: '{"Cisco-IOS-XE-native:GigabitEthernet":{"name":"1/0/1","Cisco-IOS-XE-power:power":{"inline":{"never-choice":"","never":""}}}}'
is_on_template: "{{ value_json['Cisco-IOS-XE-native:GigabitEthernet'][0]['Cisco-IOS-XE-power:power']['inline']['auto'] != NULL }}"
This works but, to monitor all 24 ports on both switches, I’m making 48 REST calls and it’s causing delays, which fills up my logs with 47 messages every 3 minutes.
2024-09-24T16:37:12.055051546Z 2024-09-24 12:37:12.054 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.cisco_core_2_port_11_poe is taking over 10 seconds
2024-09-24T16:37:12.055113717Z 2024-09-24 12:37:12.054 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.cisco_core_2_port_04_poe is taking over 10 seconds
2024-09-24T16:37:12.055189260Z 2024-09-24 12:37:12.054 WARNING (MainThread) [homeassistant.helpers.entity] Update of switch.cisco_core_2_port_19_poe is taking over 10 seconds
Finally, the question…
Is there any way to create multiple switches with a single REST query? I know I’d need to modify the query itself to remove the interface and then reference the items in the array for each switch, but that’s still better than 48 queries (I think).
I know you can do it for Sensors and Binary_Sensors in the main REST integration but Switch isn’t supported. Any idea if that’s on the roadmap or if there is a reason it just can’t work that way?
Is there some other way that I’m just too knuckleheaded to find with a search (or…a lot of searches, as the case may be)?
Any help is much appreciated. Thanks!