travisghansen / hass-pfsense

pfSense integration with Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wake On Lan not working with HA 2024.2.0

Langelus opened this issue · comments

After updating my HomeAssistant to 2024.2.0 it seems that calling Wake On Lan does not work anymore, no sure what else to provide except the log so please let me know if you need anything more from me.

-- Log --

Error executing script. Unexpected error for choose at pos 1: 'list' object has no attribute 'get'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/pfsense/services.py", line 48, in _async_send_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 843, in entity_service_call
entity_candidates = _get_permissible_entity_candidates(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 796, in _get_permissible_entity_candidates
and (entity := entities.get(single_entity)) is not None
^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'get'

-- Servicecall that has worked until now --

service: pfsense.send_wol
data:
entity_id: binary_sensor.localdomain_pending_notices_present
interface: vmx4
mac: f0:2f:54:19:3c:22

Also experiencing the same behavior in 2024.2.1. It’s not just Wake On LAN, seems like it’s something with the service configurations that are busted.

This more generic service also fails with a similar log message:

service: pfsense.exec_command 
data:
  entity_id: binary_sensor.pfsense_home_pending_notices_present
  command: ping -c 1 google.com

While we wait for a fix to this custom component, here's another way to do this with Home Assistant and pfSense. This may actually even be a better long term solution for WOL that way it isn't dependent on an API connection to pfSense. Inspiration came from here.

  1. Within pfSense, go to Services > DHCP server, select your interface, then scroll to the bottom and "Add Static Mapping"
  2. Enter ff:ff:ff:ff:ff:ff as the MAC Address, and enter an IP address that is currently unused in your network.
  3. Check the option for "ARP Table Static Entry" and save the entry. No other information is required to be entered.
  4. Call the wake_on_lan.send_magic_packet service in Home Assistant that uses the Broadcast Address as the IP address you entered in step 2, like this:
service: wake_on_lan.send_magic_packet
data:
  broadcast_address: 192.168.2.252
  mac: 00:51:ed:39:1b:ce

That works well assuming the hass installation is on the same network (generally the case)!

It does actually work across vlans even though L2 is normally not routable

That works well assuming the hass installation is on the same network (generally the case)!

This method will also work across subnets, providing pfsense has a FW rule to allow UDP traffic over port 9 between Home Assistant and the target network. You just need the static arp to be on the network where your desired WOL device is.

Yeah I used the term network too generally there. I meant more broadly physical location. ie: won’t help if you’re connected to an instance of opnsense from a hass install over the public internet (I am aware of folks who monitor many opnsense installs broadly dispersed with a single hass installation).

The PR linked below is what caused the code to break and the fix is shown in the isy994 integration code changes from the same PR: https://github.com/home-assistant/core/pull/106759/files

Should be fixed in v0.6.5. Thanks to @raman325 !