Combining the on and off automations

For every automation i use i have to make an on and off automation, i know you can combine the 2 automations for less clutter in the automations tab. Any help?

  • id: ‘1633633097257’
    alias: jonah leave
    description: ‘’
    trigger:
    • platform: state
      entity_id: person.sean
      from: home
      to: not_home
      condition: []
      action:
    • service: homeassistant.turn_off
      target:
      area_id: jonah_s_room
    • service: notify.mobile_app_joney
      data:
      message: turned everything off
      mode: single
  • id: ‘1633633342803’
    alias: jonah home
    description: ‘’
    trigger:
    • platform: state
      entity_id: person.sean
      from: not_home
      to: home
      condition: []
      action:
    • service: homeassistant.turn_on
      target:
      area_id: jonah_s_room
    • service: notify.mobile_app_joney
      data:
      message: turned everything on
      mode: single

Remove the from and to in trigger.
Then add in the actions a choose where you check if person is home, then add the call services, and then another choose and if not_home with the respective call services.

But mind that not_home is not the same as at work/school and so on.

If you want not home then do template comparison with {{ states(person) != 'home' }}

thank you for the super quick solution this is perfect for toggling everything on and off when i leave the house! Also how do you post code in that text like the font and grey highlight?

So with all you have given me this automation does work. But the only issue is with the home condition being home instead of changing to home, it cannot tell the difference between coming home and being home

alias: jonahs room
description: ‘’
trigger:

  • platform: state
    entity_id: person.sean
    condition: []
    action:
  • choose:
    • conditions:
      • condition: state
        entity_id: person.sean
        state: home
        sequence:
      • service: homeassistant.turn_on
        target:
        area_id: jonah_s_room
      • service: notify.mobile_app_joney
        data:
        message: everything turned on
    • conditions:
      • condition: state
        entity_id: person.sean
        state: not_home
        sequence:
      • service: homeassistant.turn_off
        target:
        area_id: jonah_s_room
      • service: notify.mobile_app_joney
        data:
        message: everything turned off
        default: []
        mode: single

Use “Preformatted text” in the toolbar (</>).