Please follow Community Guidelines #11 and format your configuration block properly by adding 3 backticks (```) above and below the code block, or by selecting the whole block and using the Preformatted Text button:
There are a couple issue I can see even without it formatted properly:
Both of your triggers are going to fire on every state and attribute change because you have not assigned a to or from value.
Your Or condition isn’t doing anything because it only has one condition nested under it.)
Sorry Arshad, but this hurts my eyes. Nothing in your description follows the code you are providing. Please follow the suggestions by Drew and also what you want to achieve.
From where did you get this code?
Thank you all for helping me correct my mistakes. It has only been a month since I joined the Community and
started learning about home automation. I truly appreciate all the knowledge and insights I have gained from this community.
My goal is to create a water level indicator on my home automation system. Here's how I plan to achieve it:
1. I will use three single copper wires placed in the water tank at different levels: Lower, Half, and Full.
2. I will connect these wires to digital inputs (DC 0-5V, 4-20mA) on my system.
3. The concept is as follows:
- When there is a loop between the Lower and Half wires, Digital Input 1 will be "ON," indicating that the water tank is half full.
- When there is a loop between the Lower, Half, and Full wires, Digital Input 2 will be "ON," indicating that the water tank is full.
- When both Digital Input 1 and Digital Input 2 are in the "OFF" state, it means the tank is empty.
4. I have tested this setup, and it is working well. Now, I want to automate it further.
My automation goals are as follows:
- When the state of Digital Input 2 is "ON," I want to turn off the switch.e16s_output_2.
- When the state of Digital Input 2 is "OFF," I want to turn on the switch.e16s_output_2.
- This automation should only occur between 6 AM to 8 AM and 6 PM to 8 PM since water supply is available during these times.
- If switch.e16s_output_2 is "ON" after 6 AM to 8 AM and 6 PM to 8 PM, it should be automatically turned "OFF."
trigger:
- platform: state
entity_id:`
- binary_sensor.input_2
id: "on"
- platform: state
entity_id:
- binary_sensor.input_2
id: "off"
condition:
- condition: time
after: "18:40:00"
enabled: true
- condition: or
conditions:
- condition: time
after: "06:40:00"
action:
- service: switch.toggle
entity_id: switch.e16s_output2
- if:
- condition: state
state: "on"
entity_id: switch.e16s_output2
- condition: time
after: "08:35:00"
- condition: or
conditions:
- condition: time
after: "20:54:00"
then:
- service: switch.turn_off
entity_id: switch.e16s_output2
mode: single
Thank you for the great help. I am going to use the code and monitor it for the next two days. I will provide an update on the status once the monitoring period is over.
Should the normal automation run if input_3 is off?
Should input_3 turning off for 5 minutes only turn the pump switch off during the time periods, or should it always turn the switch off?
I think you are misunderstanding how automations works in Home Assistant. The automation is event-driven, not looping continuously or waiting around for conditions to become true. If you want an automation to wait you have to tell it too do so by using one of the three Wait actions.
If you want the event of input_3’s state change to cause the pump to turn off, then that needs to be a trigger. Also, if you want input_3’s current state to affect whether other triggers cause the action to execute, you need to include it as a condition in the appropriate place.
Thank you for helping me correct my mistakes. Nowadays, I am learning about YAML and how it works in automation. Your suggested points have been really helpful for me. I aspire to become a scripting master like you.
I am sorry to bother you again, below code is not working properly - switch.e16s_output2 NOT “on”
looking for the below statement:-
when binary_sensor.input_2 is OFF turn ON the switch.e16s_output2 and when binary_sensor.input_2 is on turn off the switch.e16s_output2
between 6 to 11 pm and 6 am to 11 am
if
binary_sensor.input_3 is off for 5 minutes between 6 to 11 pm and 6 am to 11 am
Then turn off the switch.e16s_output2 again
and
Repeat the above automation after every 1 hr between 6 to 11 pm and 6 am to 11 am
Note - time change just to take more time for testing
alias: "Water-Auto-ON/off "
description: Water-Pump-Automation
trigger:
- platform: state
entity_id: binary_sensor.input_2
to: "on"
id: "off"
- platform: state
entity_id: binary_sensor.input_2
to: "off"
id: "on"
- platform: state
entity_id: binary_sensor.input_3
to: "off"
from: "on"
for: "00:05:00"
- platform: time
id: "on"
at:
- "18:00"
- "06:00"
- platform: time
id: time_off
at:
- "23:00"
- "11:00"
condition:
- condition: or
conditions:
- condition: trigger
id: time_off
- condition: time
after: "06:00:00"
before: "11:00:00"
- condition: time
after: "18:00:00"
before: "23:00:00"
action:
- choose:
- alias: Turn off switch at end of time blocks and when input_3 turns off
conditions:
- condition: trigger
id: time_off
sequence:
- service: switch.turn_off
entity_id: switch.e16s_output2
- alias: Option for sensor-based operation and start of time blocks
conditions:
- condition: state
entity_id: binary_sensor.input_3
state: "on"
- condition: template
value_template: >-
{{ has_value('binary_sensor.input_2') and trigger.id !=
states('binary_sensor.input_2') }}
sequence:
- service: switch.turn_{{ trigger.id }}
entity_id: switch.e16s_output2
mode: queued
Yes , you are correct
(input-2 indicate take is full)
(input-3 indicate there is liquid in the pipe to draw water into the tank)
(output-2 indicate water pump on/off)
What events should be triggering this automation to start pumping?
when (input-2 to OFF)
Time
hours of 6-11 and 18-23.
events that should be triggering this automation to stop pumping?
when (input-2 change to ON)
when (input-3 off for 5 minutes) — This is to avoid the water pump running without liquid
mean - when output-2 change to ON if input-3 not change ON
with a delay of 5 minutes, output-2 turn OFF
trigger:
- alias: Turn pump off when tank is full
platform: state
entity_id: binary_sensor.input_2
to: "on"
id: "off"
- alias: Turn pump on when tank is not full for 15 minutes
platform: state
entity_id: binary_sensor.input_2
to: "off"
for: "00:15:00"
id: "on"
- alias: Turn pump off if source pipe is empty for 5 minutes
platform: state
entity_id: binary_sensor.input_3
to: "off"
from: "on"
for: "00:05:00"
id: 'off'
- alias: Turn pump on at the beginning of time slots
platform: time
id: "on"
at:
- "06:00"
- "18:00"
- alias: Turn pump off at the end of time slots
platform: time
id: 'off'
at:
- "11:00"
- "23:00"
condition:
- or:
- condition: trigger
id: 'off'
- condition: time
after: "06:00"
before: "11:00:00"
- condition: time
after: "18:00:00"
before: "23:00:00"
action:
- choose:
- alias: Option for 'on' triggers
conditions:
- condition: trigger
id: 'on'
- alias: Source must have water
condition: state
entity_id: binary_sensor.input_3
state: "on"
- alias: Tank must not be full
condition: state
entity_id: binary_sensor.input_2
state: "off"
sequence:
- service: switch.turn_on
entity_id: switch.e16s_output2
- alias: Option 'off' triggers
conditions:
- condition: trigger
id: 'off'
sequence:
- service: switch.turn_off
entity_id: switch.e16s_output2
mode: queued