My understanding, from the docs, of Copy
is that it is used to create a 2nd object that will work with the same information in the original class. For example (from the docs):
# Example configuration entry
binary_sensor:
- platform: copy
source_id: source_binary_sensor
name: "Copy of source_binary_sensor"
This creates a 2nd binary sensor that will be on and off at the same time as the original. It’s an active mirror.
I’m going to be using 4 binary sensors that all work alike, but each one connects to a different switch. So can I do this:
binary_sensor:
#
#Toggle switch group first, with master switch first in that group.
#
- platform: gpio
id: "SensorSuperClass"
name: "Sensor Super Class"
number: ${DummyGPIOPinNumber}
filters:
delayed_on: 10ms
device_class: power
Then, for another sensor, do this:
binary_sensor:
- platform: copy
source_id: SensorSuperClass
id: Switch01
pin:
number: ${Sensor01GPIOPin}
mode:
input: true
pulldown: true
By overriding the pin number in SensorSuperClass, I’m using the original as a superclass to make it easy to create the 4 Binary Sensor components that are all the same, except for their ids, names, and GPIO pin numbers. (In my setup, each sensor has a lot more info than what I’ve included here - I don’t think the extra details are needed.)
If I do this, will setting the pin number in a copy override the original pin setting in the source class? Is there a problem with using this technique to create a superclass and copy it multiple times to make similar objects where each one has distinct information?
I get that if I do this, anything that happens in the superclass is copied to the subclasses, but the superclass would not be used for anything other than as a model or template for the subclasses.