Sensor.activity_state Not Triggering Automation

Good Morning Peeps,

I am very new here (First post) and still learning a lot.

My current stumbling block is that I have got my GW4 paired up with HA.
I am able to track its Activity State, one of them being “asleep”.

I would like to do some things when it detects me sleeping, but cannot figure out how to use it as a trigger.

I set up the following automation:

alias: When Jeb Falls Asleep
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.jebs_watch_activity_state
    attribute: exercise_type
    to: asleep
condition:
  - condition: time
    after: "21:00:00"
    before: "05:30:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.all_lights
mode: single

My watch indeed changed from the “passive” state to the “asleep” state within ±30min of me going to bed, but the automation was not triggered.

Trying to figure out where it’s gone wrong.
The automation still says it’s never been triggered, there are logs of the activity state changing to “asleep” and then a few hours back to “passive”.

I’m wondering if I’ve implemented the following attribute incorrectly:

    attribute: exercise_type
    to: asleep

2023-08-23 07_08_41-Logbook – Home Assistant - Brave

Go the Developer Tools → States and take a screenshot of that sensor entity including the right hand attributes column.

As requested:

And you are sure it is this attribute (currently null) that changes, not the sensor state (currently passive)?

If not, delete that line from the trigger.

1 Like

I’m not sure at all, to be honest.

When using the GUI to set up the automation, the only “trigger” I can find is a “state” change.
And the only options it gives me are “Exercise Type” and “Time”.

What would I use, if not the exercise_type, which after seeing the “Attributes” list, is definitely not the right one?
Ideally, I would need to track the “state” (middle column of the previous picture I shared), but not sure how to go about this.

Don’t use anything in the attribute box. Leave it blank. It is optional.

Thank you.
Will give that a try, feal rather dumb that it could be something that simple.

Due to the nature of it being a sleep tracker, will need to wait till morning (~24 hours) to test again.
Will report back once tested.

You can look at the state history of the sensor by clicking on the sensor or by selecting it in the history panel. That should show it it is the sensor state value or the attribute state value that changed to sleeping.