Test Button

Is there a way to create a test switch/button so that it will appear on the main HA page? This switch/button could then be routed to some new automation or something for testing. Thanks!

1 Like

Create an input_boolean.

Here is a solution!

I was looking at input boolean and it works for testing switches. But I wanted to make a button so I can test the action of a automation. I found that this can be accomplished using scripts. Sounds crazy, but it is very simple.

The main idea is that the action section of the automation is the same syntax as the sequence section in a script. So you can test with a script without all the conditions ans such to make sure your action will work by using a script. For example, I ended up doing the following.

  1. Create a script (see HA switch page here). This is probably the best documented thing in HA.

Create a script in your scripts.yaml file (included in the hass.io install) and call is something like test_script. For the first one I crated I used the Pushbullet Notify component as an output to make sure this worked. That was an easy way for me to see that this test worked.

When you want to test out a different action, you would just change the service you are using (or add a new one to make sure the script ran). Basically you would ideally put your test stuff here (hope that makes sense. See below for my example).

test_script:
  sequence:
    # this is the action to test (can change to which ever service you want
    - service: notify.Pushbullet_Notify
      data: 
        message: 'Script Worked!'

test_script_2:
  sequence:
    - service: notify.Pushbullet_Notify
      data:
        message: 'This one worked too!'

Then, because scripts do not automatically show up on the initial page, you need to add them in the groups section. Use this code in your groups.yaml file to do it.

test_overview:
  name: The Test Box
  entities:
    - script.test_script
    - script.test_script_2

Now you have a test box called “The Test Box” with “Activate” buttons that will run various scripts that you can use test the action part of automations and such. I think the best way to get into HA is to test things out like crazy. This way, you can at least test out the exciting parts! I hope this helps someone.

Ryan

Yes you can do all of that…but you can do the same thing with automations using the input boolean to trigger the automation.

When you create an input boolean it creates a switch entity in homeassistant that you can display on the frontend. It acts just like any other switch and can be used anywhere a real switch can be used.