Turning on/off network device

November 24, 2024 ยท View on GitHub

Turning ON the device

We need to have a way to turn on the device. The best way is to use magic packet to wake it up. Most of the devices with network cards do have such option.

Enable WakeOnLan on Synology NAS

Go to the Control Panel, Hardware & Power and Enable WOL

image

Adding WOL integration in HA

In Home Assistant

  • Go to Integrations
  • Press button to add a new one
  • Search for "Wake on lan"
  • Paste MAC address of your device
  • Click Submit

The above should result in a new button entity

image

Tuning OFF the device

Unfortunately there is no standard way to shutdown devices so you'll have to figure out a way to do it for the device you have.

Turning OFF Synology NAS

I think that the best way is to use the built-in integration for Synology NAS. You will need to use administrator account when adding the integration as the regular users don't have permission for triggering shutdown/reboot.

Once you add the integration you'll see bunch of devices added: one main one and one for every drive and volume you have in your NAS.

We're interested in the main device where you can find 2 buttons for sutdown and reboot

image

Device state

We need to know whether the device is on or off. There are multiple ways to achieve it.

Some router integrations expose whether the device is connected so you may have the entity telling you whether the device is on or off already.

In most of the cases the Ping integration should be good enough to achieve what we want.

In Home Assistant:

  • Go to Integrations
  • Press button to add a new one
  • Search for "Ping"
  • Paste device's IP address
  • Click Submit

image

Controlling the device

We have now everything what we need to control the device and know whether it is turned on or not. You can skip this step and use the buttons and the device state entity on your dashboards.

I prefer to have a single Switch entity which will combine all of these three we've created above.

In Home Assistant:

  • Go to Integrations
  • Press button to add a new one
  • Search for "Template"
  • Select "Template a switch"
  • In "Value template" use your state entity in the following way {{ states('binary_sensor.synology_nas') }}
  • In "Actions on turn on" section add button press action with entity for turning on your device
  • In "Actions on turn off" section add button press action with entity for turning off your device
  • You can assign this new Switch entity to the device you want. This way tt will appear on the device page.

image

Dashboard entity

I have used custom multiple-entity-row card to show the state of my NAS

image

Example confirguration

type: entities
entities:
  - type: custom:multiple-entity-row
    entity: switch.synology_nas
    toggle: true
    show_state: true
    secondary_info:
      entity: binary_sensor.synology_nas
      name: false
      attribute: last_changed
      format: relative
    entities:
      - entity: sensor.nas_volume_1_volume_used
        name: Used space