Hi!
I am using the HACS version of the OPNSense add-on so I can get access to individual firewall rules (only enabling 443 forwarding when I really need it, and auto-closing it 5 minutes later) and wireguard connections. I am struggling with the wireguard notifications. It’s working fine when I’m staring at the screen, but I wanted to set up some automations to trigger so I will be notified even when I’m not staring at the screen.
I have OPNSense in HA, and can see the wireguard server’s client couunt entity (sensor.addisonopnsense_wireguard_server_wireguard_connected_clients) is 0 when nobody is connected, and it’s 1 when someone is connected. However, I cannot figure out how to get that to be an automation trigger.
I’ve tried several things, and only gotten confusing results.
First I did the basics: from the device page, figure out the entity I’m interested in (“sensor.opnsense_wireguard_server_wireguard_connected_clients”) and then use that as a trigger for an automation. That got me this trigger:
trigger: state
entity_id:
- sensor.opnsense_wireguard_server_wireguard_connected_clients
id: Handshake!
But that goes off WAY TOO OFTEN. I see it has a spiel about ‘attributes’ in the visual editor, so I selected “clients”. But I am still getting way too many triggers… I think it’s because there is a “latest check-in” or something similar that keeps triggering the automation.
How can I get the trigger to be based on ONLY the actual count of connected clients and IGNORE the additional attributes that seem to update every 30 seconds or so?
EDIT 1:
I was able to work around the problem by setting up a single automation with six triggers, one for each of my wireguard clients. Then the action is one big Choose based on which of the six trigger.id’s was fired. Each choose has been set up with a notification to my cell with the corresponding client’s entity, where I CAN find an Attribute that presents with a 1 or a 0 depending on the status of connection.
example:
message: >-
WireGuard client {{ trigger.id }} connections: {{ state_attr(“sensor.opnsense_wireguard_client_iphone_connected_servers”,“connected_servers”)
}}
But that means I need to edit this automation every time I create a new client. That’s janky. Can anyone help me figure out how to reference the VPN SERVER’s Client Count entity? (sensor.opnsense_wireguard_server_wireguard_connected_clients)