I have a repeatable example of this happening with a switch. It’s especially noticeable with dimmers. I have several GE Smart in wall dimmers. They turn on really fast. But when turning off, they dim to turn off. Watching the state changes, I send a command to turn off the switch with AppDaemon. The light turns off but I get a state change telling me that the light is on, but dimmer. Then after a variable amount of time (sometimes up to a minute) I get another state change message telling me that the new state if off.
2017-02-15 09:45:46.798158 INFO light_control: entity light.den_fan_light, old off, new on current state{'attributes': {'supported_features': 19, 'friendly_name': 'Den Fan Light', 'manufacturer_device_model': 'ge_jasco_dimmer', 'brightness': 48, 'device_manufacturer': 'ge', 'model_name': 'Dimmer'}, 'entity_id': 'light.den_fan_light', 'last_changed': '2017-02-15T15:45:46.776951+00:00', 'last_updated': '2017-02-15T15:45:46.776951+00:00', 'state': 'on'}
2017-02-15 09:45:46.802341 INFO light_control: entity=light.den_fan_light, old=off, new=on, attributes=state
2017-02-15 09:45:46.817661 INFO light_control: entity light.den_fan_light turned on
2017-02-15 09:45:46.820790 INFO light_control: light light.den_fan_light is a dimmer. Turning light 50
2017-02-15 09:45:46.822894 INFO light_control: light=light.den_fan_light brightness=50
Turned off Light Here and physically light dimmed out pretty quick, maybe 2 seconds.
2017-02-15 09:45:55.804223 INFO light_control: entity light.den_fan_light, old on, new on current state{'attributes': {'supported_features': 19, 'friendly_name': 'Den Fan Light', 'manufacturer_device_model': 'ge_jasco_dimmer', 'brightness': 25, 'device_manufacturer': 'ge', 'model_name': 'Dimmer'}, 'entity_id': 'light.den_fan_light', 'last_changed': '2017-02-15T15:45:46.776951+00:00', 'last_updated': '2017-02-15T15:45:55.782100+00:00', 'state': 'on'}
2017-02-15 09:46:23.302316 INFO light_control: entity light.den_fan_light, old on, new off current state{'attributes': {'device_manufacturer': 'ge', 'supported_features': 19, 'friendly_name': 'Den Fan Light', 'model_name': 'Dimmer', 'manufacturer_device_model': 'ge_jasco_dimmer'}, 'entity_id': 'light.den_fan_light', 'last_changed': '2017-02-15T15:46:23.287633+00:00', 'last_updated': '2017-02-15T15:46:23.287633+00:00', 'state': 'off'}
2017-02-15 09:46:23.304790 INFO light_control: entity=light.den_fan_light, old=on, new=off, attributes=state
The timing seems to vary on when the off state will be recognized, almost like there is a polling loop that is running and depending on where in that loop I issue the off command determines how long it will take before I get an off message.