Help RESTful Switch

Hi, I have a problem with a switch command with RESTful.

  - platform: rest
    resource: http://blynk-cloud.com/5xx3axxxxxxxba47xx7d/update/V0
    method: put
    name: testblynk
    body_on: '["1"]'
    body_off: '["0"]'
    headers:
      Content-Type: application/json

This is the command I have to send, basically in the body I have to send [“1”] to activate the switch, and [“0”] to turn off the switch.

It should be an array, I do not know how to format it to insert it in the yaml.

in this way the switch is not displayed

This is the documentation for the Blynk API:
https://blynkapi.docs.apiary.io/#reference/0/write-pin-value-via-put/write-pin-value-via-put

The yaml you have works fine to send an array using an MQTT switch (I don’t have a restful switch to test with). Are you sure that it is the payload that is the problem?

switch:
    - platform: mqtt
      command_topic: switch/on
      state_topic: switch/state
      payload_on: '["1"]'
      payload_off: '["0"]'
Nov 18 10:59:40 switch/on ["1"]
Nov 18 10:59:46 switch/on ["1"]
Nov 18 10:59:49 switch/on ["1"]
1 Like

Well i’m not sure if payload is correct or not, but in that way the switch doesn’t displayed.

How can i do?

Thanks

From what I can see, blynk relies on unencrypted sensor messages going out over the internet, which is highly insecure and definitely not something I would recommend to anyone.

But if that doesn’t put you off, I was just reading the blynk documentation and I saw this

Blynk HTTP RESTful API allows to easily read and write values of Pins in Blynk apps and Hardware.
API description can be found here. Warning: Blynk HTTP API still has GEO DNS issue. This means, for now you need to use direct server IP instead of hostname in order to make it work with 3-d party services like IFTTT.

which suggests you need to find the IP of the blynk server and use that.

But personally, I would download the blynk server to your local machine, have HA connect to that, and see what its log output is when HA tries to connect.

I can try with the exposed ip, but i already have 4 restful sensor (GET) and it works perfect…

Now i will try with direct IP

Thanks for now

I just tried with the ip exposed, and again the switch does not appear …
in the log I found this error:
ERROR (MainThread) [homeassistant.components.switch.rest] Got non-ok response from resource: 400

the problem is that it seems to me to be correct… I tested the call of the rest with an online tool, and it seems to work!
I’m going crazy…

I can think of two ways to get more information.

Firstly, try enabling debug level logging for the homeassistant.components.switch.rest component. See https://www.home-assistant.io/components/logger/ This might give you more information on the message being sent.

The other way I know would be to download and install wireshark, which would enable you to inspect the packets being sent, to see how they differ. But learning how to use wireshark is a considerable task.

This is why using MQTT is preferably to http, it is so much easier to debug.

1 Like

i will convert all code to mqtt, so it’s much simple!! thanks for all!