Monday, 11 April 2022

Home Automation : Making things change

In the previous blog we set up a number of devices which we want to control within Home Assistant (HA).  The HA dashboard is available on tablet, phone or PC browser session and we can control devices there but we would prefer other/better ways of starting them.

HA  allows you to configure automations which define a trigger, conditions and an action.  The trigger could be a time or someone entering a room and conditions, for example a time range, must be satisfied before the action, such as turning on a light, is initiated.  For our first automations we choose "webhook" as a trigger.  A Webhook is initiated by a POST request from a browser anywhere on the network.  Typically the user clicks on a URL which posts a form to the HA server which causes the associated automation to be triggered.

Turn on Nest Mini Speaker

In this example we specify a webhook trigger and HA provides us with a URL for the trigger.



To determine the name of the entity we want we go into Developer Tools and, looking down the list of available entities we see there is a media_player.office_speaker
Looking at the Developer Tools services we can see what services are available for a Media Player.  In this instance, we clearly want Media_player.Turn on.

We can return to our Automation and specify we want to call a service called Media_Plaer: Turn on.

This completes the automation which we can now save.  If we click on "Run actions" in the Automations list we can check that the automation does what we want it to.


Now that our automation is working we can setup the webhook.  We can test it from the linux command line before finally setting it up as a POST form in a web page and testing it.




Load an MPD Playlist

Once we have done one automation it becomes easier to set up more.  One action I want to do is to start a playlist on the MPD entity.   The service which does this is MediaPlayer: Select Source.  You also have to specify a valid playlist as shown below.


I set this up as a script, when this script is run the associated playlist is loaded into MPD and starts playing.

We now have the ability to trigger automations from outside HA and they are verging on being useful.




No comments:

Post a Comment