Actually I think were at opposite ends of what I want to do perhaps. I don’t want the HA interface to set a switch off after I press a button on the interface, I want the HA interface to set a sensor to off in HA after a few seconds delay after the ‘on’ event, because the sensor has no ‘off’ transmission of it’s own.
I’ll continue to tinker with some ideas.
I’m not following tbh. You want to press a button, switch something on, and then it switch off again after a few seconds?
Still script…
script:
button_test:
alias: Button
sequence:
- service: homeassistant.turn_on
entity_id: THING
- delay: 00:00:03
- service: homeassistant.turn_off
entity_id: THING
Where THING is the entity ID of the device you’re switching.
Use a script and put a tiny delay in the action of that script and HA will represent it as a momentary switch.
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.
Hi, I’ve started a new topic, but I did not see where to add member tags. So the link is below.
Hi,
I hope it is still relevant - here is my solution for push button using appdaemon app:
import appdaemon.plugins.hass.hassapi as hass
class door_command(hass.Hass):
def initialize (self):
self.listen_state(self.callback, "input_boolean.push_button")
def callback (self, entity, attribute, old, new_state, kwargs):
if new_state == 'off':
self.turn_on(entity_id = "input_boolean.push_button")
else:
# do your stuff
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.
Here is a way to create the push button effect by modifying the rpi_rf module:
hope it helps.
Thanks! This is perfect for my garage door (Insteon via ISY)
I looked at a few other script examples, but this one is short, simple and works well.
Worked for me.
Will this support milliseconds?
Should do…
script:
button_test:
alias: Button
sequence:
- service: homeassistant.turn_on
entity_id: THING
- delay:
milliseconds: 400
- service: homeassistant.turn_off
entity_id: THING
Worked great! thanks Marc
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
panel_iframe:
tasmoadmin:
title: TasmoAdmin
icon: mdi:lightbulb-on
url: http://**.**.**.**
script:
button_test:
alias: Button
sequence:
- service: homeassistant.turn_on
entity_id: switch.shed_mini
- delay: 00:00:05
- service: homeassistant.turn_off
entity_id: switch.shed_mini
Define ‘not working’?
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
- momentary, which would make lots of people happy
Yeah, you don’t turn on the switch in lovelace, you run the script from lovelace.
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.