Skip to content

Create your own automations for HASPone

Allen Derusha edited this page Nov 24, 2021 · 2 revisions

While the HASPone blueprints offer a lot of functionality, the real power in HASPone is making it work for your own use cases! Here we will look at some ways to leverage HASPone in Home Assistant to trigger automations in response to button presses or to send information to the HASPone device from Home Assistant.

Triggering Home Assistant Automation from HASPone

MQTT Triggers

Several MQTT messages are sent by HASPone for every button interaction. If you click on the top button of page 1 on HASPone device plate01, the following MQTT messages will be published:

Topic Message
hasp/plate01/state/p[1].b[4] ON
hasp/plate01/state/json {"event_type":"button_short_press","event":"p[1].b[4]","value":"ON"}
hasp/plate01/state/p[1].b[4] OFF
hasp/plate01/state/json {"event_type":"button_short_release","event":"p[1].b[4]","value":"OFF"}

A few things to note here:

  • p[1].b[4] is Nextion object notation for Page 1, Button 4. See this document on how that works.
  • Each interaction sends a message on two different topics. One message is published to a subtopic of hasp/<devicename>/state/<object> with a value of ON or OFF, and one message under a shared subtopic hasp/<devicename>/state/json with the event data in JSON notation. You can use whichever message suits your current purpose.
  • One message is sent on each of those topic on button press, then another on button release

Creating an MQTT-triggered Home Assistant Automation

  1. In Home Assistant, navigate to Configuration > Automations > Add Automation, then select "Start with an Empty Automation".
  2. Name the automation something suitable
  3. Under "Triggers", select "MQTT". Set the topic to something like hasp/plate01/state/p[1].b[4] where plate01 is the name of your device and p[1].b[4] is the button you want to use as a trigger.
  4. Enter ON as the payload
  5. Configure whatever actions or conditions you'd like to complete your desired automation.

Now, pressing the assigned button on your HASPone device will trigger your custom automation!

Device Triggers

Home Assistant Device Triggers can be created for the HASPone device using the Create Device Triggers HASPone blueprint. This approach takes some setup, but makes triggering a little more straightforward when developing your automations. Otherwise, this works the same as the MQTT approach outlined above.

Deploy Create Device Triggers Blueprint

  1. Click here to import the Create Device Triggers blueprint: Create Device Triggers
  2. Select your HASPone device and then provide a list of HASPone buttons which will be used for triggers. This uses the Nextion object notation for the button names, see this document on how that works.
  3. Click "Save", and then "Run Actions" to create the device triggers (nothing visible will happen here).

Creating a Device-triggered Home Assistant Automation

  1. In Home Assistant, navigate to Configuration > Automations > Add Automation, then select "Start with an Empty Automation".
  2. Name the automation something suitable
  3. Under "Triggers", select "Device" (this will be the default).
  4. Select your HASPone device under "Device"
  5. Click the pull-down next to Trigger to find a list of the buttons you defined above, one entry for each button and one each for "pressed" and "released".
  6. Configure whatever actions or conditions you'd like to complete your desired automation.

Now, pressing the assigned button on your HASPone device will trigger your custom automation!