Question is simple, yet solution might not:
I’m looking to check when given input_select (let’s call it: “input_select.X”) was a certain value (let’s call this value “ASDF”), becuase I would like to display this as an information of when certain event happened. I would love to use that data also in some automations … but “baby steps”.
Could probably be done with an SQL sensor.
I don’t know enough about SQL or the DB schema to tell you what the query would be though.
You just create an automation that triggers on state change.
For example I have an input_select to choose between three states on my AC (Off, Cool or Heat) and triggers for each:
triggers:
- trigger: state
entity_id:
- input_select.accontrol
from:
- Cool
- Heat
to: "Off"
id: Turn Off
- trigger: state
entity_id:
- input_select.accontrol
from: "Off"
to:
- Cool
- Heat
id: Turn On
- trigger: state
entity_id:
- input_select.accontrol
from:
- Cool
- Heat
to:
- Cool
- Heat
id: Mode Change
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- Turn Off
alias: AC Turned Off
sequence:
- alias: Send Power command to AC
action: remote.send_command
metadata: {}
data:
device: aircon_lg
command: power
target:
entity_id: remote.deskremote
>>> MORE CONDITIONS <<<
I wanted to handle the different conditions differently (Turning on, Turning off and changing between Heat and Cool).
But if your requirements are simpler you could have a much simpler trigger statement, something like this:
triggers:
- trigger: state
entity_id:
- input_select.accontrol
conditions: []
actions:
....
Yes, I’ve seen your solution in other threads. I though that it was crude and did not allow to automatically go through the history.
HOWEVER,
I think it’s the only simple solution without going through db kung-fu, so I’ll mark your answer as an solution.
You are going to need to provide some details about what you want to do.
Behind the scenes Home Assistant is just a glorified event broker - events happen and trigger automations which then trigger other events.
Events can be triggered by external things happening (an IR sensor detects movement) and events can trigger real world changes (turns on a light).
All events are recorded so you can go back and look at what happened historically.
Your example does not do this though:
You could do it with triggered template sensors. e.g.
# configuration.yaml
template:
- trigger:
- trigger: state
entity_id: input_select.x
to: "ASDF"
not_from:
- unknown
- unavailable
sensor:
- name: ASDF Last Selected
state: "{{ now() }}"
- trigger:
- trigger: state
entity_id: input_select.x
to: "QWERTY"
not_from:
- unknown
- unavailable
sensor:
- name: QWERTY Last Selected
state: "{{ now() }}"
If you have many select options it could be simplified to one triggered sensor with a load of attributes, one for each option.
thanks for that.