Yeah that’s the way to do it (though I would recommend not using device triggers and actions). There used to be an example like this in the docs (it is a common question);
automation:
- alias: Turn on kitchen light when there is movement
trigger:
platform: state
entity_id: sensor.motion_sensor
to: 'on'
action:
service: homeassistant.turn_on
entity_id: light.kitchen_light
- alias: Turn off kitchen light 10 minutes after last movement
trigger:
platform: state
entity_id: sensor.motion_sensor
to: 'off'
for:
minutes: 10
action:
service: homeassistant.turn_off
entity_id: light.kitchen_light
I’m sure there are automation blueprints for this too if you search.