Thanks. Yeah I’m not sure I’m clear about it yet, but I can try the script (which I’ve never done before) and see if it does what I think I’m looking for
I’ll reword the issue just in case, and use my physical example.
I have a couple of door and window RF transmitter and want to fit many more, they communicate to HA via an 433Mhz RF hub. The RF hub only sends an ‘on’ to HA for each entity, and never an ‘off’ (because these RF transmitters have only one code). HA hassio GUI shows the door opened forever unless I manually ‘off’ it in the hassio gui. Then it’s ready to be tripped again, and do automations. I’d like either the RF hub or HA to ‘reset’ the entity back to ‘off’.
I’ve just reflashed my Sonoff RF bridge to Tasmota FW (from Espurna FW) and I’ll see if I can recreate the entities and try the script on them. I also have a DIY RFLink hub which I’m playing with.
I would start your own topic. What you are looking for is a binary sensor to automatically switch back to off. This topic is more about momentary switches.
What your are looking to do can most definitely be done. Tag me in your new topic and we can have a look.
I 100% support this, earlier when I used Domoticz we head something called “Push on/off button” that just sendt on or off commands, it was super useful and something I miss in HA.
Hi Guys
I tried this and its not woking for me
what am i missing i get the entity_id is unique to my install but
is there any thing else… alias?, button_test? that is unique.
I’ve tried the Momentary Switch Component in hacs as well and that didn’t work either
Thank you
Keep in mind that HA runs on a clock that only triggers on each second. A delay that is finished prior to then next second will not trigger when the delay is up, it will trigger when the next second happens.
Hi Marc
When I turn on the switch in the Lovelace ui it just stays latched and turns off if I click it again.
I’ve added this to my config.yaml file is that the right file
while all these “work around” are lovely I think the elegant solution would be, when defining an input_boolean and or switches, there should be a setting “type” that has 2 option:
switch, which is the default and like this all existing would continue to work
Reading this, I feel like there are two different use cases being smashed together that shouldn’t be.
I want to add a button to my HA that when pressed does the action I tell it then resets itself, ready to be pressed again. I should be able to drop that button in the UI as well as trigger that button press from automations. Example use case: Making a universal remote for a device where state can’t be effectively tracked. This would cover every button except the power button.
I want to add a switch to my HA that does not attempt to track the state of its remote device at all, not even ‘assumed state’ (most likely because it can’t). Instead when included in UI it should always present with both an on and an off button and I should be able to specify what action happens when turned on or off (after which it resets itself back to its default state of neither on nor off). As with the button, I should be able to trigger on or off on this switch from UI and automations. Example use cases: Any device with a power button where state can’t be effectively tracked.
#1 Is a script. I will admit its not intuitive to go looking for something scalled script when you think you are looking for something called button but #1 exactly describes a script. It might be worth a cookbook document describing this use case and clearly correlating it to script since enough people need it and are confused by it.
#2 doesn’t exist to my knowledge and I agree it would be handy at times. Technically you can make it work by creating two scripts, one for device_on and one for device_off. But this workaround is clunky and it would be difficult to make UI that looked nice with it. It would be nice if there was a helper specifically for this use case that then came with turn_on and turn_off services and the default UI was a button for on and a button for off.
#1 is a script, which is what we’ve been saying all along
#2 is exactly what the switch component already does for integrations where it is unable to establish the state (such as infrared remote controls)
Both platforms have been doing this since homeassistant was in its infancy, so this situation of needing a momentary switch has basically never existed, the only problem is that for some reason people can’t grasp the concept that a script can be a button on the UI no matter how many times it is explained to them.
I could literally now go to the home assistant core repo, copy the code for the script component exactly, change only its name to ‘momentary_button’ and release it on hacs and people would download it and ask for it to be added to core!
Yea I agree about the script thing. That’s why I said it might be beneficial to just include somewhere in doc that if you want a button you should make a script.
For #2, I do get that it is something switches can do but is there a way to make a generic one which does that? Like what I think people are looking for is essentially an option that works like template switch but doesn’t track state. Where they get full control over the on/off options but there’s just no actual state.
But honestly you might be right. Maybe the missing gap here is simply a cookbook. Something that says “in order to make a stateless power switch and/or universal remote here’s what you do.” Then any time the discussion comes up there is something to point to.
I use custom:button-card for my buttons, with templates for styling, but I have to admit every time I want to change something with custom:button-card, it’s not intuitive to me. And I use NodeRED for most of my automations which is amazingly intuitive.
I was unaware that a script could be inserted into Lovelace, although EXECUTE is probably not what most people want for UI.
What would be the best way to code a momentary button that looks like an entity switch?
I’m guessing: create an input_boolean, have it trigger an automation that calls a script.