Home Assistant - watch remote control
using a Restful API interface

( Last update 2025-05-16 )


Here is how, with examples for general purpose use


1. Set up access

How to create a Restful API type access to Home Assistant


2. Sample YAML code

Add to your configuration, fully functional Hall light example

3. SimpleHome Settings
How it was implemented in SimpleHome

4. Versions
Installation and current versions

General usages


SimpleHome for Fitbit watches
can be used to send these functions direct from the watch

Bookmarks can be made in browsers and added to a phone home screen

Shortcuts can be made on PCs




1. Set up Restful API  support in Home Assistant

from appdaemon.plugins.hass.hassapi

import Hass

class API(Hass):
    def initialize(self):
        self.register_endpoint(self.switch_handler, "ha_switch")
       
    def my_callback(self, json_obj, data, **kwargs):
 
        response = {"message": "Hello World"}
        return response, 200
       

Call from any browser for a test

http://192.168.1.246:5050/api/appdaemon/ha_switch

Response returned
{"message": "Hello World"}

Replace "
192.168.1.246" with your Home Assistant server IP


Back to the top

2 - Create functional commands to operate Hall light


from appdaemon.plugins.hass.hassapi

import Hass

class API(Hass):
    def initialize(self):
        self.register_endpoint(self.switch_handler, "hall_light")
       
   def my_light_handler(self, json_obj, data, **kwargs):
        self.log(f"Received data: {data}")
        self.log(f"Received json_obj: {json_obj}")
        self.log(f"Received kwargs: {kwargs}")

        # Get the command parameter from the URL
        command = json_obj.get("command", "").lower()
        response = ""

        # Control or check the Hall light based on the command
        if command == "turn_on_hall_light":
            self.turn_on("input_boolean.hall_light")
            response = {"message": "Hall light has been turned on."}

        elif command == "turn_off_hall_light":
            self.turn_off("input_boolean.hall_light")
            response = {"message": "Hall light has been turned off."}

        elif command == "check_hall_light":
            light_status = self.get_state("input_boolean.hall_light")
            response = {"message": f"The hall light is currently: {light_status}."}

        else:
            response = {"message": "Unknown command."}

        return response, 200
       

Call from any browser for a test

http://192.168.1.246:5050/api/appdaemon/hall_light?command=turn_on_hall_light

Response returned
{"message": "Hall light has been turned on."}

Replace "192.168.1.246" with your Home Assistant server IP



3. Implemented in the SimpleHome app


on


Device 5 =     

  DeviceName: Hall Light 
  DeviceIP: 192.168.1.246:5050 
  DeviceHTTP: HTTP 
  DeviceMake: HomeAssistant
  DeviceMode: Off/On 
  DeviceDate: 2025-05-02 
  DeviceOff: api/appdaemon/hall_light?command=turn_off_hall_light 
  DeviceOn: api/appdaemon/hall_light?command=turn_on_hall_light 
  DeviceQuery: api/appdaemon/hall_light?command=check_hall_light 
  DeviceState1: off 
  DeviceState2: on 
Back to the top


4. Installation and versions

Add

custom_api:
  module: custom_api
  class: API

to apps.yaml in the
\\192.168.1.246\addon_configs\a0d7b954_appdaemon\apps directory.

Add

http:
  url: "http://192.168.1.246:5050"
api:

to the appdaemon.yaml file in the
\\192.168.1.246\addon_configs\a0d7b954_appdaemon directory.



Replace "192.168.1.246" with your Home Assistant server IP


Raspberry Pi

HA Core 2025.5.1
HA Supervisor 2025.05.1
HA Operating System 15.2
HA Frontend 20250509.0
Appdaemon 0.16.7

SimpleHome V5.3.06


Back to the top