Binary sensor internal property as a variable

Hello,

Don’t know if this is possible but I am trying to dictate if an entity is internal or not based on the property of a switch. Basically changing it from internal to external on the fly. Below is an example of what I thought would work:

switch:

# Internal entities

  - platform: template
    optimistic: True
    name: internal entities
    id: internal_entities
    assumed_state: False
    restore_mode: RESTORE_DEFAULT_ON

binary_sensor:

# Relay 17

  - platform: switch
    name: "Relay 17"
    id: relay_17_i
    publish_initial_state: True
    source_id: relay_17
    internal: !lambda 'return id(internal_entities).state;'
    icon: "mdi:electric-switch"

Maybe this isn’t possible but thought I’d reach out as I didn’t find anything online.

Thank you,
DaviBoi

Usually Esphome documentation mentions “templatable” when configuration option is dynamically configurable with lambdas

do you get an error:?
This option is not templatable!

Yeah unfortunately I do. Didn’t know if there was a way around this. Thanks for the insight!

Why do you want to do this?

it seems like a very strange question to ask.

1 Like

Strictly bandwidth. With all entities enabled, the esp will “miss” state updates. Not typically a problem having only choice entities enabled but there are choice times for debugging where having all entities enabled would provide benefit.

DaviBoi

How many entities do you have?

The API is very efficient. That should not happen.

For example, sending the RPM or speed read from a canbus will shutdown the API to where it it wont update any entities. The canbus is running at 125kb but the data is being updated multiple times a second. Having just those two enabled is enough to bring it to a halt. My data connection is roughly 5mbit-10mbit

You can throttle the updates sent to HA.

https://esphome.io/components/sensor/index.html#throttle

For that specific example that would work. However, i am experiencing incorrect states for gpio switches and binary sensors when I get past 75 entities. Ive been able to manage it but was looking for a quick way to enable and disable exposed entities to HA without manually having to enable each individual one.