Command line switch that toggles based on status in Node-Red

Hi guys,

I’m just getting started using HA and would like to begin with automating my lights. I can control and get status for my lights using “http get”, here’s an example:

To turn on a light:

http://[webswitch address]/relaycontrol/on/[a number]

To turn off a light:

http://[webswitch address]/relaycontrol/off/[a number]

check light state:

http://[webswitch address]/relaystate/get/[a number]

this will return

|000|OK|0|

for “off” state and

|000|OK|1|

for “on” state

Now, I have written a simple python script to check if light is on or off and I have configured HA to show buttons for controlling the lights.

switch:
  - platform: command_line
    switches:
      golv_led:
        command_on: "/usr/bin/curl -X GET http://192.168.1.236:8080/relaycontrol/on/1"
        command_off: "/usr/bin/curl -X GET http://192.168.1.236:8080/relaycontrol/off/1"
        friendly_name: Golv LED

problem is I don’t know how to check the state of the lights and represent the change in HA. I’m thinking I should use Node-Red to check the status every second or so because there are other devices controlling the lights outside of HA as well but would need some help with the first one.

Besides status checks I’d like to:

  • change the name from “switch” to “Lights” in the dashboard
  • change from two icons “on” and “off” to a toggle switch
  • change icon to lightbulb. I’ve tried adding “icon: mdi:lightbulb-outline” but that didn’t work