Need help creating automation where I compare 2 attribute states

Hello,

I am new to HA and would like to create an automation with my Harmony hub.
I hava an entity remote.harmony_hub which has 2 attributes I would like to compare: current_activity and previous_activity

I would like to trigger an automation when current_activity != previous_activity ; but I cannot figure out how to do that.

Basically I would like to do something like this:

if 
current activity is not equal to previous activity:

then 
if 'previous activity' is not 'empty' (meaning everything was off)
   if 'previous activity' is 'xyz'
      perform actions for ending xyz  ->
   if 'previous activity' is 'xyz2'
      perform actions for ending xyz2

if 'current activity' is not 'empty' (meaning everything is off)
   if 'current activity' is 'xyz'
      perform actions for starting xyz
   if 'current activity' is 'xyz2'
      perform actions for starting xyz2

Can all of this be done with an automation that checks for ‘if current activity is not equal to previous activity’ and then call a script where I do some further tests and enable/disable lights, power outlets etc?

Some pointers:

That is a state trigger: Automation Trigger - Home Assistant
The entity you’re looking after is likely named remote.harmonyhub or similar

“off” is a state of its own for Harmony Hub

You can retrieve the previous state in an state trigger via the trigger.from_state variable: Automation Trigger Variables - Home Assistant (home-assistant.io)