Current sensor to show state of lamp and be able to trigger the switch On or Off

# binary sensor config
binary_sensor:
  - platform: remote_rpi_gpio
    host: 192.168.1.195
    scan_interval: 10
    ports:
      12: V1
# relay config
switch:
  - platform: remote_rpi_gpio
    host: 192.168.1.195
    invert_logic: true
    ports:
      03: Relay Kitchen
# switch template config
switch:
  - platform: template
    switches:
      kitchen:
        value_template: "{{ is_state('binary_sensor.v1', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.relay_kitchen
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.relay_kitchen
# light config
light:
  - platform: switch
    name: Kitchen Light
    entity_id: switch.kitchen

This should be correct but its not behaving as it should. Ideally if my sensor triggers then by my light config the bulb should be on or off depending on the state of the sensor. The switch config should not toggle the relay but only do so when I toggle it.
I hope I have the correct understanding because what I am trying to do is tell the state of the lamp regardless if my physical switch is pressed and there by be able to not disrupt mess it up when I toggle the relay.
thanks much tom you have shed a lot of light on situation

That all looks correct.

Not sure what you mean by “mess up”.

Your switch will react to changes made in home assistant or by the physical switch as you have a voltage monitor for feedback.

The problem may be that you have not correctly wired the relay and physical switch to both be able to control the light. The switch and relay can not be simply wired in series, or in parallel. It requires this configuration:

Thanks very much,

Messed up means mixed states so my logic don’t get messed up as it is getting mixed up.
I have 2 way wiring but a bit different from yours

That is essentially the same wiring. So you’re good to go. You should be able to control the light from either the switch or relay.

So I had a chance to check it and it does not work as it should at all. The Light config is able to see the correct state of the bulb when it is ON/OFF. But the slider does not do anything at all to the relay to control it from under the Light card. Similarly the Template command is also not able to change the state when I move the slider slider either. Form the above the only control I get is using the switch command for the relay only.

What slider?

It’s not a dimmer it’s a switch (relay).

sorry the switch tab that moves like a slider on off.

agreed its not a dimmer.

I just dont understand what im missing to get the on off to work in my template or light cards

Made some more checks and I have no control on either the switch template or my light. The lamp icon on the light works flawless with the light activation and the switch corresponds with the light icon status. But if I try to move the switch to off if the light is on, it goes to the off position momentarily and then switches back on. What am I missing that will allow me to get control of the light and not have it stay locked to what ever state the voltage sensors is in?

This is used to determine the state of the switch:

value_template: "{{ is_state('binary_sensor.v1', 'on') }}"

Checking that would be a good place to start.

This is used to change the state of the switch:

        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.relay_kitchen
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.relay_kitchen

So check that as well.

hello again Tom

So check through everything and realized because im using 2 way switching I needed to change my command from Switch to a Toggle and it all works fine.

Seems however that my sensors that are connected to my raspbian pi directly on GPIO pins are unable to be reliably detected by REMOTE pi command from my HA running on my next PI 3. If i encounter a power failure im stuck with my sensors not being detected and sometimes end up having to do multiple shutdown of both rasbian and HA pi and hope they play together. This is my new nightmare
Two questions come to mind as many have said their remote Gpio detection works flawless so is that because they are using the HA on docker on a virtual environment?
I have been looking at flyt method over mqtt and wanted to know if that may be a more reliable and viable method

thanks much again to all for the assistance

I’ve used flyte’s gpio to mqtt app on two raspis (nearly all gpio) faultlessly for years.

don’t have to tell me twice taking the dive now

Did a fresh install of latest raspbian buster
configured relevant settings remote gpio,ssl, location etc

python --version

showed ver 2.7 so ran

nano ~/.bashrc

then edited with

alias python='/usr/bin/python3'

did below to reset

source ~/.bashrc

then a recheck of python version and showed 3.7
then used

sudo apt-get update
sudo apt-get install python3-pip

then edited to make python3 default with below

alias pip=pip3

then tried to add flyte items with

pip install pi-mqtt-gpio

Got the below error

Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://www.piwheels.org/simple/cerberus/

So did and upgrade with

pip install -U pip

retried flyte package and was able to download all the items including Cerberus but i got a new error

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with ‘-m pip’ instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pi-mqtt-gpio

AND then this

WARNING: The script pi_mqtt_gpio is installed in ‘/home/pi/.local/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

I want to start building but I would like to know if you encountered any of these errors or how are you getting around the install without them being a problem?

thanks again

I followed the VM install instructions on flyte’s github. This was the only issue I had:

I removed pip latest version and did a reinstall of flyte command and no errors and all went well.

I cannot seem to find any instructions as to where the config.yaml file must reside on the rasbian pi.
I require some assistance on this part

So I am trying to create a file in my usr/bin/python folder and its being denied
The software part on the pi and navigating and creating files and folders are clearly my challenges.

I put it in a folder called /mqtt in my /home directory. You can put it anywhere as long as you tell the program where the config file is when you execute it: GitHub - flyte/mqtt-io: Expose GPIO modules (Raspberry Pi, Beaglebone, PCF8754, PiFace2 etc.) and digital sensors (LM75 etc.) to an MQTT server for remote control and monitoring.

did not use the virtual environment install…
did everything as above and updated just the pip3 from the correct location command and the error was gone.

Rebooted and ran the service and it ran and everything works flawless and seamless I was definitely missing out all along and can most definitely say this is by far the most relaible and seamless sensor detection method I have tried thus far. I have tried a HA instance with my sensors directly connected to Gpio on that Pi, then tried HA with a remote connected pi with sensors directly connected to Gpio on the remote pi and I have even tried Gpio2 custom components. I was never able to get reliable detection with any of them and I have spent quite some time tinkering in each method trying to make sure everything was done correctly and properly.

With everything and all the help I have received thus far is seems I always have another hurdle to cross and its now trying to get the systmd method to auto run the service on t reboot…I am getting a option to enable root or pi requiring a manual feedback. I guess python and tinkering remains my area of greatest challenge sigh.
but progress as slow as it may be is still progress and I appreciate all the assistance thus far

I have the same problem with my remote system sensor monitoring for the pi. Never solved it. If you are interested in monitoring your remote pi cpu memory etc this is a good option with discovery: Remote RPI system monitor

However I restart it so rarely that I’ve actually had to write down the startup instructions because I forget them in the intervening time (year+).

I never ended up using the virtual environment install method. Instead I was directed by some really smart guys to do the following and I hope it helps anyone here.
I defined the python environment following this

The versions numbers will of course have to be changed to the ones your system has and then the latest version set as default ( auto) in the whole system

Do an install for user pi

pip install pi-mqtt-gpio

create the config.yaml file

then for system wide

sudo -i
pip install pi-mqtt-gpio

create script file for run on startup using init.d method
nano /etc/init.d/mqtt.sh

-----insert the following------

#!/bin/bash
### BEGIN INIT INFO
# Provides:          sample.py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     S 2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO
sleep 5s
/usr/bin/python3 -m pi_mqtt_gpio.server /home/pi/config.yaml >> /var/log/mqtt_server.log 2>&1 &

then

sudo reboot

the sleep time of 5 sec was added to allow for any services that was not available on boot. When we used zero seconds service fails.

I asked anilet for some feedback on his system which uses master/ slave HA instances for additional implementation of room sensors with mqtt gateway but I know you already hooked on esp home.
Care to share any reasons why you opted for this method?

and any responses to the question I asked peter

thanks again