Controlling the Tasmota SonOff Switch with HTTP and Node-Red

http-requestTasmota devices can be controlled by both HTTP and MQTT. If you don’t have an MQTT broker or don’t want to use one then you can still control your Tasmota devices using node-red.

To do this we will use the http request node which is one of the core nodes.

The  http request node can be used for.



  • Retrieving web pages from a website
  • Making API Requests
  • Sending and receiving JSON data to a website or API.
  • etc

The node will send a request and receive the response and it handles both the request and response.

In the HTTP request node you can set the:

  • Request Method -GET,POST etc
  • URL
  • SSL
  • Authentication
  • Proxy
  • Keep Alives
  • Return Data

As shown below:

node-red-http-request-node

The request method and URL as well as other settings, like content headers, can also be set in the preceding node for creating dynamic requests.

The output is usually a web page but for our Tasmota switch it is JSON. If we leave it as a string means we will need to convert it ourselves to a JavaScript Object.

Turning a Switch On and OFF Simple Flow

Below is a screen shot of the basic flow.

tasmota-node-red-http

The flow is effectively two flows. The top flow using inject nodes to send the command. The inject node labelled ON looks like this:

inject-on

You can see that we use the IP address of the switch and pass the command in the url. See controlling smart home devices using http.

The bottom node using dashboard buttons for on and off and also displays the status. The status is returned as a JSON string and needs to be converted to a JavaScript object to be displayed.

tasmota-display-off

Video Controlling Tasmota Sonoff Switch using HTTP and Node-Red

Resources

Control Tasmota Switch with Node-Red HTTP

 Related Tutorials:

 

Please Let me Know if you found it Useful
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published. Required fields are marked *