Use 'from_state' state value in a Automation as a condition?

Is it possible to use the ‘from_state’ value in an automation’s condition??

I have the issue that a simple state change is also triggered from a ‘unavailalable’ states. But I only care when there is a state change of actual ‘number values’.

Hi @walter-ve

I made this automation which may do what you want. The key part is the condition.

alias: Test automation
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - input_number.test_number
    above: 50
conditions:
  - condition: template
    value_template: "{{ trigger.from_state != 'Unavailable' }}"
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: Triggered
mode: single
1 Like

That condition is incorrect. It will always be true.

The only way to use from_state is through a template. Keep in mind, only specific triggers will have from_state, so make sure you choose the correct trigger when attempting to use from_state in a template.

The proper way to check the state in a condition is:

trigger.from_state.state

using trigger.from_state returns the state object, not the state of the entity. The state object is a “object” that stores all sorts of information about the previous state, including the state itself.

Lastly, you can likely skip conditions all together by using not_from in your trigger. IIRC it’s only available in yaml.

- trigger: state
  entity_id: sensor.abc
  not_from: 
  - unknown
  - unavailable
1 Like