Connecting Instances (Switch)

I have my main HA instance on a virtual machine of my ESXi host. When I made this change I lost the ability to use the GPIO pins of my Raspberry Pi to send 433mhz signals to my RF switches. I would like to get these working again using a Pi Zero W I recently picked up and my old hardware. I can also put a temp sensor / pir sensor ect. on it and use those also.

I was able to get the temp sensor reporting to my main HA instance using the restful sensor component. It works well and suits my needs for that item. However, I want to be able to control the switches from my main instance, write my automations there etc.

The implementation of the master/slave setup for multiple HA instances appears to be broken at best. Ive seen a few people report success, however, more seem to report issues.

How is anyone else handling a setup like this? MQTT, rest seem like good avenues. I am thinking of using a restful switch on my main instance that (if I understand the docs correctly) should be able to get the status and post a command to turn on the switch via the Pi.

It seems like MQTT would need more setup and doesn’t seem as easy to me. However, I know MQTT can be very useful and I wouldn’t mind diving into it if someone had an example to get me started.

Looks like @PtP used the command line switch with some success. I may make this my first attempt tonight, although I am still interested in how others have implemented this. My main concern is keeping both HA instances up to date. The main instance is what I use to control everything, however, the Pi instance will ultimately have the state of and control of the actual switches.

@silvrr

I have been using this for some time now and it works great. I currently have 8 devices connected to 2 different machines that I pull into my main HA instance.

My only complaint is that lights cannot be dimmed (easily).

I typically don’t update the remote instances very often as long as the devices on there are working good.

I am updating mine today because I had some time to kill at work. I can ssh into both instances so it pretty easy to do.

Good luck!

1 Like

[quote=“PtP, post:3, topic:20700, full:true”]

I have been using this for some time now and it works great. I currently have 8 devices connected to 2 different machines that I pull into my main HA instance.

My only complaint is that lights cannot be dimmed (easily). [/quote]

Thanks for the update. My switches are just on/off so this should work well. I’m hoping I can write the code once and then copy/paste the rest with a few updates as I have 5 switches to make. Should be able to.

I tend to do the same for my main instance to, if it’s not broke don’t mess with it. I was on version 43 until a day or so ago when I needed a new component.

so I put together the following and it works…kind of.

  rfswitch1:
    command_on: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_on?{"entity_id":"switch.rfswitch1"}
    command_off: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_off?{"entity_id":"switch.rfswitch1"}
    command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch1
    value_template: '{{ value_json.state == "on" }}'
   
  rfswitch2:
    command_on: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_on?{"entity_id":"switch.rfswitch2"}
    command_off: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_off?{"entity_id":"switch.rfswitch2"}
    command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch2
    value_template: '{{ value_json.state == "on" }}'
    
  rfswitch3:
    command_on: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_on?{"entity_id":"switch.rfswitch3"}
    command_off: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_off?{"entity_id":"switch.rfswitch3"}
    command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch3
    value_template: '{{ value_json.state == "on" }}'
    
  rfswitch4:
    command_on: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_on?{"entity_id":"switch.rfswitch4"}
    command_off: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_off?{"entity_id":"switch.rfswitch4"}
    command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch4
    value_template: '{{ value_json.state == "on" }}'

  rfswitch5:
    command_on: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_on?{"entity_id":"switch.rfswitch5"}
    command_off: /usr/bin/curl -X POST http://192.168.1.30:8123/api/services/switch/turn_off?{"entity_id":"switch.rfswitch5"}
    command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch5
    value_template: '{{ value_json.state == "on" }}'

The issue is that if one light is turned on it turns on all of them, not sure what I got wrong here.

What happens if you run the command from terminal?

Do the individual switches work from the frontend of the pi instance?

mmm, Ill have to try that tonight, see if the result is different.

From my pi instance the switches work as expected. Its only the command line switch control that seems to be acting up.

I will try to run some tests on my stuff.

Here is the way am doing now. It appears to differ from my original post.

  mcfront_porch_fan:
    command_on: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"light.aeotec_dsc27103_micro_dimmer_2nd_edition_level"}' \http://192.168.5.58:8123/api/services/light/turn_on
    command_off: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"light.aeotec_dsc27103_micro_dimmer_2nd_edition_level"}' \http://192.168.5.58:8123/api/services/light/turn_off
    command_state: curl -X GET http://192.168.5.58:8123/api/states/light.aeotec_dsc27103_micro_dimmer_2nd_edition_level
    value_template: '{{ value_json.state == "on" }}'
1 Like

Much appreciated.

1 Like

Winner winner chicken dinner. Up and running now, thanks @PtP

Code for anyone looking into this in the future.

   - platform: command_line
    switches:
      rfswitch1:
        command_on: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch1"}' \http://192.168.1.30:8123/api/services/switch/turn_on
        command_off: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch1"}' \http://192.168.1.30:8123/api/services/switch/turn_off
        command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch1
        value_template: '{{ value_json.state == "on" }}'

      rfswitch2:
        command_on: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch2"}' \http://192.168.1.30:8123/api/services/switch/turn_on
        command_off: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch2"}' \http://192.168.1.30:8123/api/services/switch/turn_off
        command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch2
        value_template: '{{ value_json.state == "on" }}'

      rfswitch3:
        command_on: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch3"}' \http://192.168.1.30:8123/api/services/switch/turn_on
        command_off: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch3"}' \http://192.168.1.30:8123/api/services/switch/turn_off
        command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch3
        value_template: '{{ value_json.state == "on" }}'

      rfswitch4:
        command_on: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch4"}' \http://192.168.1.30:8123/api/services/switch/turn_on
        command_off: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch4"}' \http://192.168.1.30:8123/api/services/switch/turn_off
        command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch4
        value_template: '{{ value_json.state == "on" }}'

      rfswitch5:
        command_on: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch5"}' \http://192.168.1.30:8123/api/services/switch/turn_on
        command_off: curl -X POST -H "x-ha-access:" \-H "Contentype:application/json" \-d '{"entity_id":"switch.rfswitch5"}' \http://192.168.1.30:8123/api/services/switch/turn_off
        command_state: /usr/bin/curl -X GET http://192.168.1.30:8123/api/states/switch.rfswitch5
        value_template: '{{ value_json.state == "on" }}'
1 Like