Command switch to firewall command to DD-WRT router over SSH

Glad you got it going!

Not familiar enough with DD-WRT to advise you on this. I run a different router firmware. Maybe nmap?

With some switches you can set an initial state, but I don’t see that in the documentation for command_line switches, so you may need to use an automation to set the state at startup. Something like this:

automation:
- alias: 'HA_Start'
  trigger:
    platform: event
    event_type: homeassistant_start
  action:
    service: homeassistant.turn_on
    entity_id: switch.alleycat_iphone

Keep in mind this will execute your command as well, which may not be exactly what you want.

What I would do here is create a bash script that takes input from your command line switches so that you can reuse it. The script below accepts two arguments, and passes them along to your router.

<stopvalve.sh>:

#! /bin/bash

"ssh [email protected] iptables -R grp_10 1 -p 0 -m mac --mac-source $1 -j $2; ssh [email protected] iptables -R grp_10 2 -p 0 -m mac --mac-source $1 -j $2"

You can add as many devices as you wish to toggle by repeating the format below.

Switches:

streetcat_ipad:
  command_off: "/path/to/stopvalve.sh 24:24:0E:AA:BB:CC REJECT"
  command_on: "/path/to/stopvalve.sh 24:24:0E:AA:BB:CC ACCEPT"
  friendly_name: Street Cat-iPad

alleycat_iphone:
  command_off: "/path/to/stopvalve.sh E0:C7:67:ZZ:YY:XX REJECT"
  command_on: "/path/to/stopvalve.sh E0:C7:67:ZZ:YY:XX ACCEPT"
  friendly_name: Alley Cats-iPhone

Good luck!

1 Like