How can I trigger this automation more efficently?

platform: state
entity_id:
  - input_text.status_gate
to: close
for:
  hours: 0
  minutes: 0
  seconds: 6

I have an automation that is triggered by this statement.

In other environments this could usually be accomplisched by using a variable instead of a text input box.

if variable: status_gate == close, trigger the automation

Is it possible to use variables like this in home assistant?

Please state what you’re trying to achieve.

2 Likes

I made an automation that changes the input_text based on the status of a gate. If the gate is opened then the input_text is set to “open”, after some seconds the input_text changes to “close” if there is no signal from the gate.

This works but it is inefficent. I would like to be able to use a variable instead of writing and reading values from input_text.

What and how is the input_text changed to close?

ps: isn’t input_text.status_gate considered as a variable? :thinking:

But what’s the point of this input_text in relation to the automation?
Why don’t you just trigger on the state of the gate directly? If it’s a binary sensor, there is no need for any variable, the state is always “on” or “off”.

Exactly my point :grin:

1 Like

I have an esp32 plugged to the gate motor, when the gate is opened the esp is active and sending periodic mqtt messages to my home assistant server. When the device is powered off it means the gate must be closed or it is closing.

All of this because I want to remotely know my gate status and I can also trigger automations based on that.

That still does not clarify why you are using an input_text.
HA can read your MQTT message directly and create appropriate “normal” sensors.

In this case, I guess it should be a plain binary sensor, actually.
There are even specific device classes for doors, for proper icons.

When the gate is closed the esp doesn’t send an “off” signal because it is not powered. That’s why input_text comes in. After some seconds if there is no “on” mqtt signal it means the esp is off and then the gate is closed.