Can it be done HA change State of pin from physical Momentary Switch?

I never had an issue with esp gpios till now. Then again the length of the wire is a major issue with all these device. At times they pull more current which could damage the gpio, which I have experienced.

But since you already had the arduino working before, it would be best to go with it. Besides that if you are using arduino, you really wont need HA for this thing. Wont it be able to run this automation without HA. I know I can do that with esp.

The gpio problems with rpi is a bit tricky to solve as the voltages are very small, a small amount voltage leaking can make the switch floating.

ah ok well the wires are only the lenght of like 10 " or 12 they are the project wires so its not even working on my table to test it… i didnt wanna run 2 devices or least a smaller

so you mentioned your having esp gpios issue what issues is that? as i was thinking getting esp or the other to solve the issue of this hanging

but then again i never truly watched when linked from ardunio to RPI if the rpi would hang binary sensor… i just know everytime it rebooted it would trigger the Ardunino with that floating voltage you helped me figure out there…
i just know i could click on and off with the button and didnt have an issue in the ardunino but i figured i could make it smaller with those esp you mentioned then i could run it from the usb power and then power the LEDs and switch but then again maybe it will kill the power
i found running the ardunino uno 1 led rpi wouldnt boot up HA it kept rebooting i guess it was sucking power

as for the ardunino from what i learned anyways you gotta program it and you cant just edit like HA ill still need HA beside it…
ardunino you can program tmers i guess but its has no internal clock really and your limited
so ardunino i had was to control a Servo orginally… since Home Assistant cant use servos.
and no website for the ardunio

so i was hoping to put it all on the Rpi… RPI works great if u click it from website… but just doenst like switchs least not momentary… i guess using a real toggle switch
or from the examples i seen they only make it like an inch wiring or the jumper cables
but could it be the HA thats the issue?

the examples all just use Raspbarian and python script to use switchs

could it be the HA to the devices

and i guess ill try HA OS instead of running HA on raspbian
ill try the HA OS version see if thats the issue

i am testing the HA/Raspbian on the real setup thats working from HA main but i dont have a button installed… so that communication doesnt work right with reading a switch

so ill give it a test today… running HA as an OS not the supervised… maybe its not able to read through the 2 different programs at once

probably why its unsupported lol…, but ill give it a try today if i get a chance and do a comparison

Well I used about 3 meter wires for a switch, it was working great for a week or so but then it stopped working and i found out that due to the length of wires, the switch drew more current which destroyed the gpio. I didnt learn this the first time but only on the third loss. :sweat_smile: After this i have never used longer wires

I was talking about timers here. The advantage of esp is that even when it doesnot have an internal clock, it can get time from any ntp server local or cloud based. It can more or less work independently. In fact for some time my esp devices were working without HA.

I have a water pump setup now but its a bit advanced. I have a water level sensor also so that my pump only switches on when the water level is below a point in my water tanks. I also have a routine to start the pumps daily at 6 and turn them off before over flowing.

Please convert the binary sensor to a switch like what we started from the first and see what happens. With a switch, even if the state get stuck on ON position, we can turn it off with switch.turn_off.

ah ok
so i did try running HA as an OS so no raspbian it did not help… it would still get stuck
i never did try a resistor to the ground i seen as i didnt wanna pull the other projects apart

ya i plan to do water sensor too as i pumping water out of a 2" hole drain so i wanted to put the sensor down in there… beside the hose that sucks out… my mother uses those long match sticks to take a reading how much water is in the drain…

but with the ESPs these all work on wifi i didnt see any with a nic… as thats why i liked the PI because i have never liked wifi… wifi always goes down it can get interrupted if you walk or close a door… so i had to buy my mother a new wifi router… the 2.4 ghz failed but the 5.0ghz stayed up… and i use TPlink light switch to turn on and off my mothers hot water tank to save money… so she can turn off right beside the tank and not stand on a chair to turn off the breaker at panel… and i can turn it off with HA… but if the wifi fails then those esp no good? or can it get the time but still runs schedules on it?
i never dabbled i still learning as i go… and so far running HA ontop of Raspibian i had a couple hickups… Double Nic DHCP requests. Time Zone conflicts HA and raspiban having 2 different time zones…
but its working for Caller ID /HA Pump Timers… been running it since i mentioned… just didnt get the switch issue… but ill give it a try today

i wouldnt mind seeing your setup for water level etc… as for my setup id have to do it all in a 2" hole and i looked at those Fork kinda sensors but i read how they dont give accurate readings etc… so i just stuck with the run ever 21 2 4 hours for 15 min etc

but ill give that a try change it to a switch and see what happens

so changing from binary sensor to a switch does nothing
when i touch the wires together they dont do anything

if i do Binary sensor and switch to gpio 4
it the switch still wont toggle but the binary sensor does but still gets stuck on every so often

would you think raspberry pi forum would know? or is it a HA issue i cant resolve it? as i figured maybe if i write over there forum they might know too?

Its a good idea, you should certainly do that. I am sure they would have users who have faced the same issue.

so i seemed to finally get it working…
i had done testing over from the raspberry pi forums.

and then i testing HA but it wasnt working 100% still glitching…
i ended up just formating installing raspbian installing HA and pasted just the buttons
and i changed pull_mode: up and all that seemed to fix it it doesnt hang i also found HACS with the token when i remmed it out worked better… it just seemed everything was glitching
so i did a just a clean install and works
… i dunno why HA people went with Debian and not stick with Raspbian i confused why its no longer supported…

but i have a couple questions i stuck… i got it up and running… with Caller ID in the background

but i changed my idea
instead of 1 LED being on to show power
i changed it to
RED = PUMP OFF
GREEN = PUMP ON

so when you press a button it toggles and that works kinda
i did invert logic to get the RED led to come on when you boot up HA… but is there a way to set it to ON instead of OFF in the toggle switchs?

2nd issue i run into
i use a Button Card you seen… it reads the State of the pump relay to say On off

but i need it to also run a script at the same time to toggle the LEDS but also read relay to say the state of the Button card

right now it works detecting as a switch… i tried to add a 2nd ennitty underneath the first one when you save it it erases it.

how can you use a button it runs a Script and changes the status of the card by the status of the relay…

other then that seems to be working ok just having issues with the LED’s toggling from the website and the button

but its working now i also changed to GPIO 8 the fan hat/shield i using seems to have disabled GPIO 4 so i wasnt able to use it …

You can try a config like this.

type: 'custom:button-card'
entity: switch.pump_relay
icon: mdi:cube
tap_action:
    action: call-service
    service: script.led_toggle
show_state: true

Please change the entity_ids in the above config.

So now the red led comes on when the HA boots and it turns off when pump switches on while green led turns on. Is this what is happening now? But if you want to invert this, you can do it with the help of a automation which looks into the state of the relay and toggles the led accordingly.

Or simply you can connect this led to the relay trigger pin of the rpi which means that the led will be bound to the relay operations in the hardware setup and we dont need to have scripts or anything to control it. It will switch on when the relay is on and switch off when the relay is off.

i tried ur code with mine well i modified mine… as i had toggle as tap action but couldnt get it to work tells me my script is not found

but what i want if possible
i already invert RED LED so ON is really off when it boots up but it be nice to have it so when HA boots up it toggles the switch to ON its not important it just helps me visually see
as the script i made toggles the LEDS
so Red is on when Pump is off… and Green is Off
and when pump is running then Red goes off and Green Comes on

this is my custom button card… its not liking my script and i copied from developers page so its copied right… and it works if i run the script by the run button

type: horizontal-stack
title: null
size: 10%
cards:
  - type: 'custom:button-card'
    color_type: card
    icon: 'mdi:pump'
    name: Sauna Pump<br>Offline
    entity: switch.h_sauna_pump
    tap_action:
      action: call-service
      service: script.sauna_pump_switch_toggle_leds_too
    styles:
      card:
        - font-size: 20px
        - height: 150px
        - width: 145px
        - color_type: card
        - color: 'rgb(255,255,255)'
    state:
      - value: 'off'
        name: Sauna Pump <br>Off
        color: 'rgb(255, 0, 0)'
      - value: 'on'
        name: Sauna Pump <br>On
        color: 'rgb(0, 128, 0)'
      - value: unavailable
        name: Sauna Pump <br>Offline
        color: 'rgb(0, 0, 128)'

You havent added show_state: true Please see the last line in my config.

And with automation you can do like this.

alias: Led Notification
description: ''
mode: single
trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id: switch.h_sauna_pump
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.h_sauna_pump
            state: 'off'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.red_led
          - service: switch.turn_off
            target:
              entity_id: switch.green_led
      - conditions:
          - condition: state
            entity_id: switch.h_sauna_pump
            state: 'on'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.red_led
          - service: switch.turn_on
            target:
              entity_id: switch.green_led
    default: []

Please change the entity_ids and also since the logic is inverted you might have to change the switch service accordingly.

ill try tommorow the automation one
ok i added the show state… it still gives me the eror
Failed to call service script/sauna_pump_switch_toggle_leds_too. Service not found.
as i already have 3 show states for Switch … but when you click the button its failing
below is the entire button card code

the 3 states i have on off unavaliable are to show the state of h_sauna_pump switch
but when i said i added part of your code
i changed mine
tap_action: toggle
to
tap_action:
action: call-service
service: script.sauna_pump_switch_toggle_leds_too

and it wont run the script

type: horizontal-stack
title: null
size: 10%
cards:
  - type: 'custom:button-card'
    color_type: card
    icon: 'mdi:pump'
    name: Sauna Pump<br>Offline
    entity: switch.h_sauna_pump
    tap_action:
      action: call-service
      service: script.sauna_pump_switch_toggle_leds_too
      show_state: true
    styles:
      card:
        - font-size: 20px
        - height: 150px
        - width: 145px
        - color_type: card
        - color: 'rgb(255,255,255)'
    state:
      - value: 'off'
        name: Sauna Pump <br>Off
        color: 'rgb(255, 0, 0)'
      - value: 'on'
        name: Sauna Pump <br>On
        color: 'rgb(0, 128, 0)'
      - value: unavailable
        name: Sauna Pump <br>Offline
        color: 'rgb(0, 0, 128)'

and this is my toggle automation script for button on screen
script for website Button card

this is the script yaml

alias: sauna pump switch toggle leds too
sequence:
  - service: switch.toggle
    target:
      entity_id:
        - switch.h_sauna_pump
        - switch.led_pump_on
        - switch.led_pump_off
mode: single

this is the automation yaml for the physicial button

alias: Toggle Switch when Button is pressed
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.pump_switch
    from: 'off'
    to: 'on'
condition: []
action:
  - service: switch.toggle
    target:
      entity_id:
        - switch.h_sauna_pump
        - switch.led_pump_on
        - switch.led_pump_off
  - service: script.turn_off
    target:
      entity_id:
        - script.15_min_pump_on
        - script.20_min_pump_on
        - script.30_min_pump_on
mode: single

so right now it works for PHysical Button with the reverse logic
but home Assistant reads it as OFF but i want HA to read the RED led toggled to the ON position when you boot up home assistant not to the off position is there anyway to force it

for now i had to do reverse logic to get it to come on on boot up but shows up as off

sorry dislexia i dont explain things right.

ill try the automation tommorow

Please check if the entity_id is correct. You can check this in the developer console tab. At times instead of name, some numbers are used in entity_id.

Remove the inverse logic and all the actions regarding leds in the physical button automation and add the automation for led that i shared in the previous post and try.

ok i managed to figure it out i changed it a big i got rid the script
and went back to a Toggle switch… because the LED Notification you made that took care of that …
without your help id be still stuck i tried to learn as i go…

i did figure the script issue i was having and what you ment by number
since i have issues updating HA it usually has error and says check supervisor logs

i takes like 3-4 times to update HA Core or the other part

but what i did was i copy yaml. delete the automation … create it and paste then save… then it gives me a Number… i bet the reason for the number is each time you change the title it links it to a number instead of the orginal title named for that automation…
so i was able to fix that … so all seems to be working i didnt do it to it all…

now i havin issues i not sure how to google search it
i tried to figure how you Group cancel
so if i toggle 1Hr 15min run Toggle Switch it cancels the other 11 Toggle Switchs forces it off
and vice versa… i not sure how you write if you toggle 1 switch in these group of defined switchs turn them all off
without having to write 12 scripts to turn them off

i tried to add it to the Automation 12 i made but then i clued in they will only turn off once the automation starts… not at the instant of you toggling the switch…

what do i google search or is it a script or automation?
so you see in the pic i have 2 of the toggles on but i want to do Toggle 1 and it toggles the others off

or do i need a something special but least its coming nicly once i its all working flawlessly i gonna make a backup incase i ever have to reinstall things…

is it a Template i need to do? i still learning that stuff too… i did look up switch but i didnt find what i looking for

and if its not possible thats ok… i just make sure i dont keep 2 activated at once… i probably make the changes anyways my mother likes the push button working so far ill have to take pics of it later
i do know i need to change my IoT ac/dc relay it over heats and trips safey running the pump sometimes… so gonna make something better… but least she can press the button and i have safety so if she forgets to shut off it automaticlly
and shes already pumped 3000 liters of water of her basement in 24 hours

i appreciate the help so far most appreciative and the time you taken to help me too
i like this program i just cant get my head around alot of it… and i still cant get node red to work yet i hear its so much easier ya when it works for ya lol

oh and you mentioned you have a similar setup with water sensors … what do you have? i also looking to add water sensor in the hole with the suction and i have a barrel i pump water into i want to add a sensor when the water fills up too fast and my stand up sump pump is covered by water and over flowing the barrel it shuts off my pump thats pumping water out of a drain

Instead of going for eleven switches and operations, there is another way you can work it out and it does need only one switch and two input_number entity. I will explain it first and tell about the original question you asked.

In this setup we need a switch that would say if the automated pump operations are enabled or disabled. Then we can have two number sliders like the below. Here you can select numbers from 0 to 240. Both these sliders are to select the minutes of the pump operations. The number set in the first slider will determine when to switch on the pump like 90 or 11 etc. The second slider will soecifiy the number of minutes the pump should be kept on during this operation. If you feel that this could be helpfull, we can work it out easy. The advantage is that you can select any range of times and you wont have to care about writing many scripts.

Now if this is not good, I will talk about the original question, how to turn the rest of the switch off when a switch is toggled on. This can be done with a single automation like this.

alias: New Automation
description: ''
trigger:
  - platform: state
    entity_id:
      - switch.switch1
      - switch.switch2
      - switch.switch3
      - switch.switch4
    to: 'on'
condition: []
action:
  - service: switch.turn_off
    target:
      entity_id: >-
        {% set string = "switch.switch1, switch.switch2, switch.switch3,
        switch.switch4"%} {% set box = trigger.entity_id %}
        {{string|regex_replace(find= box, replace= 'switch.dummy',
        ignorecase=true)}}
mode: single

Just change the entity_ids of the switches to your present switches. You dont have to change the switch.dummy or create a new switch. It is just a dummy entity_id to satisfy the condition. I have only added 4 switches, you can extend it to as many as you like.

ah ok well i wouldnt mind both?? as i have it… and these be my pre defined options then… and then i could do a different one to make it adjustable…

i tried your code i couldnt get it to work… if i toggle say the first switch it wont un toggle all the switchs so i can still toggle all 9 switchs to on… my dislexia i wrote 12 earlier i ment 9
so i not sure what i doing wrong?
cuz what i wanted to do is
if i toggle 1hr 15min… and then i go toggle 2hr 20min it then untoggles 1h15min… and then when i toggle 4hr 30 min then it will untoggle 2hr20min…

but here is my yaml… i used ot to the switchs i set… well they are not switch. but i used automation.

alias: testing toggles
description: ''
trigger:
  - platform: state
    entity_id:
      - automation.every_1_hour_quit_after_15_min
      - automation.every_1_hour_quit_after_20_min
      - automation.every_1_hour_quit_after_30_min
      - automation.every_2_hour_quit_after_15_min
      - automation.every_2_hour_quit_after_20_min
      - automation.every_2_hour_quit_after_30_min
      - automation.every_4_hour_quit_after_15_min
      - automation.every_4_hour_quit_after_20_min
      - automation.every_4_hour_quit_after_30_min
    to: 'on'
condition: []
action:
  - service: switch.turn_off
    target:
      entity_id: >-
        {% set string = "automation.every_1_hour_quit_after_15_min,
        automation.every_1_hour_quit_after_20_min,
        automation.every_1_hour_quit_after_30_min,
        automation.every_2_hour_quit_after_15_min,
        automation.every_2_hour_quit_after_20_min,
        automation.every_2_hour_quit_after_30_min,
        automation.every_4_hour_quit_after_15_min,
        automation.every_4_hour_quit_after_20_min,
        automation.every_4_hour_quit_after_30_min"%} {% set box =
        trigger.entity_id %} {{string|regex_replace(find= box, replace=
        'switch.dummy', ignorecase=true)}}
mode: single

The thing is that you said these are switches and so I used the switch.turn_off command but these are automations so instead of switch.turn_off we need to use automation.turn_off service. And also change the dummy switch to automation. This would make the automation loo like this.

alias: testing toggles
description: ''
trigger:
  - platform: state
    entity_id:
      - automation.every_1_hour_quit_after_15_min
      - automation.every_1_hour_quit_after_20_min
      - automation.every_1_hour_quit_after_30_min
      - automation.every_2_hour_quit_after_15_min
      - automation.every_2_hour_quit_after_20_min
      - automation.every_2_hour_quit_after_30_min
      - automation.every_4_hour_quit_after_15_min
      - automation.every_4_hour_quit_after_20_min
      - automation.every_4_hour_quit_after_30_min
    to: 'on'
condition: []
action:
  - service: automation.turn_off
    target:
      entity_id: >-
        {% set string = "automation.every_1_hour_quit_after_15_min,
        automation.every_1_hour_quit_after_20_min,
        automation.every_1_hour_quit_after_30_min,
        automation.every_2_hour_quit_after_15_min,
        automation.every_2_hour_quit_after_20_min,
        automation.every_2_hour_quit_after_30_min,
        automation.every_4_hour_quit_after_15_min,
        automation.every_4_hour_quit_after_20_min,
        automation.every_4_hour_quit_after_30_min"%} {% set box =
        trigger.entity_id %} {{string|regex_replace(find= box, replace=
        'automation.dummy', ignorecase=true)}}
mode: single

ah ok my bad when i said switchs as you can see in the pic beside each is a toggle switch… thats what i mean switchs by each program is a toggle switch…

my bad i sure dont know how to explain myself on this site… didnt mean to confuse you… and thats aweseome its working …

so could you tell me how that code works… so the first part… takes in account all enity cards on the screen if you flick it on… and the second part switchs off all of them or one of them… i dont understand waht the set box regex replace all that means

still alot for me to learn… i have more ideas of something else i wanna add but ill do that after i get this all figure out

now could u show this slider? or can you do a digital Timer with Up and Down Arrow for Hour Min Sec
not too fussy figured i see it before on other things if cant

id like to try this slider you talked about too.

do you use that for your own program?

Now with the input number method. We first have to make two input sliders which can be done by copying the following to the configuration.yaml

input_number:
  pumping_interval:
    name: Pumping Interval
    min: 0
    max: 600
    step: 1
  pump_timer:
    name: Pump On Timer
    min: 0
    max: 60
    step: 1

Then you can have these entities as sliders in the dashboard.
The automation should look like this.

alias: Pump Variable Timer
description: ''
mode: single
trigger:
  - platform: time_pattern
    minutes: /1
condition:
  - condition: template
    value_template: >-
      {{(now().hour * 60 + now().minute) %
      states('input_number.pumping_interval')|int == 0 }}
action:
  - service: switch.turn_on
    target:
      entity_id: h_sauna_pump
  - wait_template: '{{ states(''input_number.pump_timer'')|int *60 }}'
    continue_on_timeout: true
    timeout: '{{ states(''input_number.pump_timer'')|int *60 }}'
  - service: switch.turn_off
    target:
      entity_id: h_sauna_pump

You should also add this automation to the earlier all toggle automation so that if any one of them is toggled on this should be toggled off and vice versa.