Controlling gpio port 11 with gpio port 12 connected to PIR sensor

I have a light connected to Port 11 and want to control it with Port 12.
Would it be possible, and what would the configuration be?

You will need both of these in your configuration.yaml:


Then an automation might look like this:

- alias: turn on light when PIR senses motion
  trigger:
    platform: state
    entity_id: name.of_your_PIR
    to: 'UP'
  action:
    service: light.turn_on
    entity_id: name.of_your_light

Hi PtP

Thank you for the reply. I am completely new to this so I thought it would probably be better if I just post the code from the config file. Unfortunately, I couldn’t get it to work properly yet. Switching the light from the Home Assistant interface does infact turn on the LED, but switching from it the actual switch wired to the GPIO does not work. There seems to be no compile errors in home assistant at least. This is how it is configured at the moment:

#Raspberry Sensor

binary_sensor:
platform: rpi_gpio
ports:
11: PIROffice
pull_mode: “UP”
bouncetime: 50
invert_logic: true

# Raspberry Switch

switch:
platform: rpi_gpio
ports:
12: LightDesk
invert_logic: true

New config

alias: turn on light when PIR senses motion
trigger:
platform: state
entity_id: binary_sensor.piroffice
to: ‘ON’
action:
service: switch.turn_on
entity_id: switch.lightdesk
invert_logic: true

A few things…

When posting code use the option < / > in the tool bar to show the proper spacing.
In your automation you put “invert_logic: true”. That is part of your component setup and not needed in your automation.

Look at the states (<>) in the development tools from the front end. What state does binary_sensor.piroffice show? The developer tools is very useful and can help you learn about the capability of a component.

You can try changing invert_logic to false in your sensor setup. You might also try another GPIO port that is generic and not shared with another function like GPIO17.

Okay. I removed the “invert_logic: true” from the automation component. From the development tools page the binary_sensor.piroffice state shows Off. If I press the button of the switch it changes to On, but it does not switch the other port.

I also tried changing the invert_logic to false on the sensor config side, but to no avail. Tried using one of the generic GPIO ports also to no avail.

Is it possible to switch a GPIO port with another GPIO port in Home Assistant?

What does it say in your logs?

If you can see the state of the sensor change in HA and control the light from HA then the problem is in the automation. Check spacing, and entity_id names as well.

Apologies for the late reply. Attached are the screenshots of the states page, log file and configuration.

So the states changes in HA if manually triggered correct?

I do see some issues in your yaml for the automation.

It should look like this…

automation:
- alias: turn on light if motion is detected
  trigger:
    platform: state
    entity_id: binary_sensor.piroffice
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: light.lightdesk