Home Assistant API - Turn On/Off Light via simple (HTTP) command from other device

I know this works but obviously requires a new IT hub with MQTT capabilities. They make a Tuya version and a Tuya/ESP32 combo ir/Zigbee/IR/RF hub. There is multiple options with this like tasmota (buy the tasmota version) but I think this will accomplish what you are trying.

https://a.aliexpress.com/_mtuhQAs

Example

I have for years use this for Fibaro but canā€™t find the same for HA sadly

http://alxa:[email protected]/api/callAction?deviceID=907&name=turnOff

I see the Idea with the red node, but surely a direct API call or HTTP is faster and more easy ( as in less things that might go wrong )

Hey, I know itā€™s been a long time since this post, but just FYI I was able to get your command working by adding ā€œAuthorization: Bearerā€ right before the key. So that line would be:

-H "Authorization: Bearer yourKeyHere"

Seems to work after that. For whoever might find this post.

Also got it working as a templated rest command in configuration.yaml, just sharing for the record:

rest_command:
  send_command:
      url: "http://YOUR_SERVER_ADDRESS/api/services/{{ type }}/{{ command }}"
      method: POST
      content_type: "application/json"
      payload: '{"entity_id": "{{ entity_id }}"}'
      headers:
        authorization: "Bearer YOUR_KEY_HERE"

Use in an automation:

  action:
    service: rest_command.send_command
    data:
      entity_id: "switch.master_bedroom_lamps"
      type: "switch"
      command: "turn_off"

I am currently building a new HA instance with Z-wave, replacing Insteon, and this allows me to install new switches a few at a time and keep everything working through my original instance in the meantime.

1 Like