Need help converting rest api command into RESTful Switch

For a while I was using curl with command_line (until I created some custom platforms that replaced the need for that), and what I did was to put that part in a file and then used curl’s -K option to point at that file. Let me know if you need more detailed help in making that work.

Hi pn. You have already been so much help already I don’t want to bother you anymore. Plus it is not that urgent. At least it is working now. I just thought if there was and easy way to concatenate the secret into the curl statement I would go ahead a do it. But it sounds like it is not that easy as apparently the command line can’t interpret concatenated strings with a variable.

This DLI Power Switch also supports MQTT. Unfortunately, I have not used MQTT before so I went for this curl solution first as it “appeared” to be easier. As soon as I can get the MQTT Broker installed on my hass.io instance and figure out how to use it then I plan to try and setup MQTT Switches as a longer term solution. Not sure how difficult it is to use MQTT, but I guess I will find out. I will probably be back when I get stuck on that… :slight_smile:

Thanks again for all the help. Have a good weekend.

Andrew j

Always glad to help.

FWIW, I haven’t used MQTT yet either. So far everything I’m interfacing with is either Z-Wave or networked based (either on my LAN, or cloud servers), so I really haven’t had the need to play with MQTT. Good luck with that! But don’t worry, there are plenty of people with MQTT experience on this forum willing and able to help! :slight_smile:

I’m not on any form of HASS.io. I went old school and installed in a Python venv directly on top of Raspbian. FWIW, I followed these instructions for creating a persistent path.

If you need help getting that working you should start a new topic.

You should really create a new topic for this. I can tell you that when I initially set up my z-wave stuff it was indeed very confusing. I recall the system required multiple restarts for everything to get recognized and for all the entities to get created. But I also needed to change/customize some things, and that part was also very confusing. I also know that since I did that some of the z-wave initial setup functionality has changed. So, honestly, I really can’t help you with this. Sorry.

Good point. Let me delete my last post and I will start a new topic.

I think that after reading this post there is still hope for my current states for my light switches that I have in HA :
I managed to integrate the switches of my home automation system and add it to HA. These are toggle switches that I can acces with curl. I found a command I can send to get the current state :

command_state: "curl 'http://192.168.0.141:8080/login/validate/' \
-XPOST \
-H 'Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5' \
--data 'login_username=xxx&login_password=xxx' -L  http://192.168.0.141:8080/entry/0/4/"

When I send this command on a Mac in terminal this is my return or output /

a little explanation about :
entry/0 = for the states
/4/ is the group of the lights
/action/6640 = is the id of the light ( pay attention in the screenshot above where you can see for action/6640 when the light is on it shows li-negative

And this is how it looks on a webpage : action/6640 is shown as Led vensters :

So so what can be a valid value_template in addition to command_state?

command_on: “curl ‘http://192.168.0.141:8080/login/validate/
-XPOST
-H ‘Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5’
–data ‘login_username=xxx&login_password=xxx’ -L http://192.168.0.141:8080/action/6640/

    command_off: "curl 'http://192.168.0.141:8080/login/validate/' \

-XPOST
-H ‘Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5’
–data ‘login_username=xxx&login_password=xxx’ -L http://192.168.0.141:8080/action/6640/"

    command_state: "curl 'http://192.168.0.141:8080/login/validate/' \

-XPOST
-H ‘Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5’
–data ‘login_username=xxx&login_password=xxx’ -L http://192.168.0.141:8080/entry/0/4/"

    value_template: "{{ value|lower }}"

I’ve been looking for this for a while to get this working but it just won’t work :roll_eyes:

I have done some tests here but with this configuration my light goes on and off every 30 seconds.
Is this related to the value_template?

Led_vensters:
        command_on: "curl 'http://192.168.0.141:8080/login/validate/' \
-XPOST \
-H 'Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5' \
--data 'login_username=xxx&login_password=xxx' -L http://192.168.0.141:8080/action/6640/"

       
       
        command_off: "curl 'http://192.168.0.141:8080/login/validate/' \
-XPOST \
-H 'Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5' \
--data 'login_username=xxx&login_password=xxx' -L http://192.168.0.141:8080/action/6640/"

        command_state: "curl 'http://192.168.0.141:8080/login/validate/' \
-XPOST \
-H 'Cookie: PHPSESSID=r72foce4u77rraj3be3mv8nam5' \
-H 'Accept:application/json' \
--data 'login_username=xxx&login_password=xxx' -L  http://192.168.0.141:8080/entry/0/4/../../../action/6640"

        value_template: "{{ value }}"

Am I on the right track here?

Have you made any progress?

In case you haven’t figured it out already, the way the command state works is to periodically send that command and then examine what’s returned. The default rate is 30 sec. You need to find a command that can return the state without changing it. What you have above apparently is not only getting data to examine to determine the current state, but is also changing it (i.e., toggling the light) at the same time.

sorry for the delay:
solved with the help from pergola.fabio

Did you ever find a solution for using a credential/password from the secrets.yaml file in a command line command?

Unfortunately not. I am still embedding my password in the curl command for my Digital Logger Web Switch. I tried using MQTT, but found it to be unreliable for this switch.