Rest Command not working

Hi,

I trying get this rest command working but it’s not populating as entity.

# Rest Command Door

rest_command:
  7545door:
    url: https://7545.example.net/fcgi/do?action=OpenDoor&UserName=user&Password=password&DoorNum=1
    method: POST
    headers:
        accept: "application/json, text/html"
        user-agent: 'Mozilla/5.0 {{ useragent }}'

That’s because it will be available as a service that you can then for example call from an automation.

How can make it into a switch?

There is a restful switch for that. However this requires your switch to support receiving the desired switch state in the payload of the request, not as query parameter.

If that does not work with your particular rest service, but your original rest command does work, you could try combining all that into a template switch which lets you call a service (=rest command) for each state.

When I put that url into a browser door unlocks, that’s all I trying to archive. Possible using a toggle switch maybe…?

I am not fimilar with this stuff

I guess it comes down to what kind of control you need - if you only need to unlock the door and want some UI control, the fastest option may be to keep that rest_command and embed it into a script. The script would just call that rest command service, and you can then add the script as an entity to your user interface.

Do you also have a way to “CloseDoor”, and a way to retrieve from the API if the door is opened or closed?
If so, a restful switch, like @exxamalte mentionned, is the way to go.

If you cannot determine whether the door is opened or closed, a rest service, called by a button on the UI, for instance, is probably what you want.

Using this url: https://door.example.net/api/relay/trig?mode=0&num=1&level=1&delay=5 I can get the door open, How can I make it into a button, using basic http authentication.

This is response I get from that url

{ "retcode": 0, "action": "trig", "message": "OK" }

mode  0:Auto Close 1: Manual
num   1 Relay A 2 Relay B 3 Relay C
level 0 NO - COM 1 NC - COM
delay 0~65535(Second)

@exxamalte I got the switch part working, only the state part is not working. But I am able use the state on sensor.7545_door_status 0 for closed 1 for open. Also rest switch is repeating it repeating it self, I think due to the state is missing.

Can I make it the state work like this

is_on_template: "{{ states('sensor.7545_door_status) | int = 1 }}"

This is response I get from this url https://door.example.net/api/relay/trig?mode=0&num=1&level=1&delay=5

{ "retcode": 0, "action": "trig", "message": "OK" }

- platform: rest
  resource: https://door.example.net/api/relay/trig?mode=0&num=1&level=1&delay=5
  name: 7545 Door Switch
  verify_ssl: false

chrome_2N5Nak81LI

There are two small issues - there is a quote missing at the end of the entity ID. And the comparison must use two equal signs:
is_on_template: "{{ states('sensor.7545_door_status') | int == 1 }}"

Hi,

Button remains grayed out and it keep triggering it continually.

chrome_6D8zPyRivG

- platform: rest
  resource: https://door.example.net/api/relay/trig?mode=0&num=1&level=1&delay=5
  name: 7545 Door Switch
  verify_ssl: false
  is_on_template: "{{ states('sensor.7545_door_status') | int == 1 }}"

Don’t you have a link to the relay API documentation?
It’d be easier than trying to guess…

This is the document I have

https://drive.google.com/file/d/1JzrzoW93jfVSYkmv_bpz6K-LeU8Sgmov/view?usp=sharing

What the definition of that one?

It’s state 0 for closed, 1 for open

The HA definition, I meant. The code…

Here

  7545_door_switch_status:
    friendly_name: "7545 Door Switch Status"
    value_template: "{{ state_attr('sensor.7545_door_api_status', 'RelayA') }}"
- resource: https://7545.manjot.net/api/relay/status
  scan_interval: 2
  sensor: 
     - name: "7545 Door API Status"
       json_attributes_path: "data"
       value_template: "door"
       json_attributes:
           - "RelayA"

I can’t see which one of those would result in an entity with id sensor.7545_door_status.

It appears as if you need the following in your rest switch configuration?
is_on_template: "{{ states('sensor.7545_door_switch_status') | int == 1 }}"

It keep triggering it self every 5 seconds, once I press the switch in HA

- platform: rest
  resource: https://door.example.net/api/relay/trig?mode=0&num=1&level=1&delay=5
  name: 7545 Door Switch
  verify_ssl: false
  is_on_template: "{{ states('sensor.7545_door_switch_status') | int == 1 }}"

Does it do something different when you call that url in, e.g., a browser?