Get previous state from a sensor

I have a state sensor for a washing machine which will provide me information on the current course in a sensor. For example, at 10:00 the state will be “Normal” and then when it finishes at 10:10, it turns to “Finished”. I need a way to capture that state as it was at 10:00, or to make it simple, the state that it was 10 minutes ago, this way I can reference this in an automation that will trigger after the washer is complete. How do I get the value of the sensor from 10 minutes ago?

Making your trigger use the " from " and " to " state doesn’t fill the requirement?

1 Like

Thanks, but I think it’s a little more complex than that, since my trigger is when the washing machine has been off for 1 hour. I want to keep that trigger as is, and then simply have a condition, such as if last run cycle was NOT Tub Clean, continue automation, otherwise stop the automation.

Here’s the automation for reference:

alias: Laundry - forgot to move clothes to dryer
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.washer
    to: "off"
    for:
      hours: 1
      minutes: 0
      seconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.dryer_dry_completed
    state: "on"
    for:
      hours: 0
      minutes: 45
      seconds: 0
action:
  - service: notify.ios
    data:
      message: Did you forget to move the clothes to the dryer?
      title: "🧺 Laundry Alert! "
mode: single
1 Like

How do you use the SQL query? Do I need to add a SQL plugin? Is the query then added as a template? I cannot find any help for inclouding the query it in an automation.

SQL queries can be added in the Integrations page (Settings > Devices & Services > Integrations), just click the “Add Integration” button and search for SQL. This will create a sensor entity you can refer to in scripts, automations, or templates.