Trying to turn light on/off using a switch and one automation

I’m working on a simple example, using a switch to turn a light on or off with one automation. I’ve seen examples of if, else, endif processing but can’t seem to get it to work.

I think I want to set up my automation something like this:
(please forgive my pseudo code)

trigger:
   switch.hallway on
   switch.hallway off
action:
   if is_state(switch.hallway, on)
      homeassistant.turn_off 
            switch_hallway
   if is_state(switch.hallway, off)
      homeassistant.turn_on
            switch.hallway

I know I can do this with two automations, but I don’t want two automations for each of my switches.

Any examples or topics I can read will be most helpful.

Thanks!

I recently answered this exact question here: