Pin is used in multiple places

With the risk of being told to read the documentation, I have, and am not an experienced coder, so…

Although this recommendation does work for some devices (I successfully fixed one device using this), it does not seem to work for:
- platform: ultrasonic

This is my code for the ultrasonic sensors before adding any fixes:

sensor:
  - platform: wifi_signal
    name: "Sump Pit Water Depth Sensor WiFi Signal"
    update_interval: 60s
    
  - platform: ultrasonic
    trigger_pin: GPIO14
    echo_pin: GPIO12
    unit_of_measurement: "%"
    icon: "mdi:water-percent"
    accuracy_decimals: 0
    update_interval: 5s
    name: "Sump Pit Water Depth"
    
    filters:
      - lambda: return ((0.53-(x-0.03))/0.53)*100;
      - filter_out: nan

  - platform: ultrasonic
    trigger_pin: GPIO14
    echo_pin: GPIO12
    update_interval: 5s
    name: "Water in Tank"
    unit_of_measurement: "l"
    accuracy_decimals: 0
    
    filters:
      - lambda: return (1-((x-.03)/0.53))*108;
      - filter_out: nan

When I try to add allow_other_uses: true it flags an error:

[allow_other_uses] is an invalid option for [sensor.ultrasonic]. Please check the indentation.

If I indent it one tab it throws the following error at line 1 of the code:

Invalid YAML syntax: mapping values are not allowed in this context in “”, line 47, column 23

Any suggestions are appreciated.

1 Like

I must admit that I re-used Pieter Brinkman’s water meter code, but looking at the HA Energy Dashboard it seems that the Pulse counter is not of importance, except for debugging/calibration purposes. Water meter total is the only measurement used for the dashboard.

Unfortunately I’m unable to test the code currently.

1 Like

How did you try to add allow_other_uses: true? Following the the same syntaxis as for the pin: schema this would be the correct syntax I suppose:

sensor:
  - platform: wifi_signal
    name: "Sump Pit Water Depth Sensor WiFi Signal"
    update_interval: 60s
    
  - platform: ultrasonic
    trigger_pin: 
      number: GPIO14
      allow_other_uses: true
    echo_pin: 
      number: GPIO12
      allow_other_uses: true
    unit_of_measurement: "%"
    icon: "mdi:water-percent"
    accuracy_decimals: 0
    update_interval: 5s
    name: "Sump Pit Water Depth"
    
    filters:
      - lambda: return ((0.53-(x-0.03))/0.53)*100;
      - filter_out: nan

  - platform: ultrasonic
    trigger_pin: 
      number: GPIO14
      allow_other_uses: true
    echo_pin: 
      number: GPIO12
      allow_other_uses: true
    update_interval: 5s
    name: "Water in Tank"
    unit_of_measurement: "l"
    accuracy_decimals: 0
    
    filters:
      - lambda: return (1-((x-.03)/0.53))*108;
      - filter_out: nan
1 Like

Awesome, thank you @MJV that worked perfectly. As I said, still learning and wasn’t aware the pin’s could be listed both ways (inline and indented below).

1 Like

You don’t need to use ultrasonic twice. Once you have the distance you can calculate the rest with a template sensor.

2 Likes

Can you give an example to do this?

What I had in mind is something like this

sensor:
  - platform: ultrasonic
    trigger_pin: 
      number: GPIO14
    echo_pin: 
      number: GPIO12
    update_interval: 5s
    internal: true
    id: waterdist

  - platform: template
    lambda:
       return ((0.53-((id(waterdist).state)-0.03))/0.53)*100
    name: "Sump Pit Water Depth"
    accuracy_decimals: 0
    unit_of_measurement: "%"
    icon: "mdi:water-percent"

  - platform: template
    trigger_pin: 
      number: GPIO14
      allow_other_uses: true
    echo_pin: 
      number: GPIO12
      allow_other_uses: true
    update_interval: 5s
    name: "Water in Tank"
    unit_of_measurement: "l"
    accuracy_decimals: 0
    lambda: return (1-(((id(waterdist).state)-0.03)/0.53))*108
   

Or alternatively a copy sensor…

Typically I have the “raw” sensor which I mark as internal after set-up/debugging and then use copy sensors with filters for the processed results. I find it clean to debug and maintain like that.

I edited my last post, the idea is to use the ultrasonic sensor once only, give it an id and then refer to it by id for further calculations. I may have some indentations etc wrong, but the idea is there.

I am not overly familiar with the copy integration, but Mr Mahko is often right.

1 Like

I’d just like to emphasise that only using ‘allow_other_uses=true’ didn’t work for me (first snippet below, wrong)

pin: GPIO13
     allow_other_uses: true

I had to rearrange the sensor (advanced mode) and use ‘number’ too:

pin: 
      number: GPIO13
      allow_other_uses: true

Maybe this hint saves some time for someone as inexperienced as me.

1 Like

The same thing was covered just a few posts back: Pin is used in multiple places - #47 by MJV.

You either have a simple pin definition using only the pin number, or you have a pin section with several options under it. Your’s is an invalid combination.

Yes, just like it says in the docs!

Nope. Why would they do that when they can come here and have someone explicitly answer their question or write their code without having to make the slightest effort to help or educate themselves.

1 Like

Hi Rob,
I am not an expert, but guess this is a question how you define your pin. I originally had the pin: A0 with same error likey you had when adding “allow_other_uses: True”. I then changed pin definition like below in alle places.

  - platform: adc
    # pin: A0
    pin:
      number: GPIO17
      allow_other_uses: True
1 Like

Don’t reuse the pin. See Pin is used in multiple places - #51 by nickrout

Very nice, thanks for the hint Oldacres, it works now, herewith entire code for the easy way

sensor:
- platform: pulse_counter 
  pin: 
    number: GPIO18 
    allow_other_uses: true 
  update_interval : 6s 
  name: "Water pulse" 
  id: Water_pulse

- platform: pulse_meter
  pin: 
    number: GPIO18 
    allow_other_uses: true
  unit_of_measurement: 'liter/min'
  name: 'Water Pulse Meter Liter'
  icon: 'mdi:water'
  total:
    name: "Water Total"
    unit_of_measurement: 'liter'

- platform: pulse_meter
  pin: 
    number: GPIO18 
    allow_other_uses: true
  name: "Water Pulse Meter"
  unit_of_measurement: "liter/min"
  icon: "mdi:water"
  total:
    name: "Water Meter Total"
    unit_of_measurement: "m³"
    id: Water_meter_total
    accuracy_decimals: 3
    device_class: water
    state_class: total_increasing
    filters:
      - multiply: 0.001

- platform: template
  name: "Water Usage Liter"
  id: water_flow_rate
  accuracy_decimals: 1
  unit_of_measurement: "l/min"
  icon: "mdi:water"
  lambda: return (id(Water_pulse).state * 10);
  update_interval: 5s

I have no idea why multiple pin uses is such a common issue. Theres only a few cases where that would be OK to do and thats only if the Copy integration or a Template wont work. Why someone would use the same ADC pin twice, i surely have no idea about that one.

I want to push the same button differently, then I need the same pin not only twice but multiple times.

1 sec = ON/OFF
5 sec = 1 Hour runtime
10 sec = 2 Hours runtime
15 sec = 3 Hours runtime

How do I do that when I can only program that pin only once?

switch:

  • platform: gpio
    pin: GPIO32
    name: ON/OFF
    id: relay1
    on_turn_on:

    • delay: 1000ms
    • switch.turn_off: relay1
      icon: “mdi:water-plus”
      interlock: [relay2]
  • platform: gpio
    pin: GPIO33
    name: Flush
    id: relay2
    on_turn_on:

    • delay: 1000ms
    • switch.turn_off: relay2
      icon: “mdi:water-sync”
      interlock: [relay1]
  • platform: gpio
    pin: GPIO25
    name: Tak Spotter
    id: relay3
    icon: “mdi:spotlight”

  • platform: gpio
    pin: GPIO26
    name: LED List
    id: relay4
    icon: “mdi:led-strip-variant”

  • platform: gpio
    pin: GPIO32
    name: 1 hour
    id: make1h
    on_turn_on:

    • delay: 5000ms
    • switch.turn_off: make1h
      icon: “mdi:water-plus”
  • platform: gpio
    pin: GPIO32
    name: 2 hours
    id: make2h
    on_turn_on:

    • delay: 10000ms
    • switch.turn_off: make2h
      icon: “mdi:water-plus”
  • platform: gpio
    pin: GPIO32
    name: 3 hours
    id: make3h
    on_turn_on:

    • delay: 15000ms
    • switch.turn_off: make3h
      icon: “mdi:water-plus”

I was writing something wrong…
Replacing the line “pin: GPIO32” with this worked :slight_smile: :

pin:
  number: GPIO32
  allow_other_uses: true

You do it by not using Switch. You need to be using binary_sensor.

You can do multiple actions for a single binary_sensor aka button by selecting multiple min/max times as well as single click, double click, multi-click if you want or need as well.

I highly suggest familiarizing yourself with the documentation. Browse through it and see whats available, what does what, like the difference between Switch, Button, and binary_sensor etc.

Here i use 1 button for 2 lights. 1 is basically a single button push(50ms -350ms) and the other is more of a “push and hold” that triggers the second light(action).

binary_sensor:
  - platform: gpio
    pin:
      number: 13
      mode:
        input: true
        pullup: true
    name: "Bedroom/Porch Switch"    
    filters:
    - delayed_on: 10ms
    on_click:
    - min_length: 50ms
      max_length: 350ms
      then:
       - homeassistant.service:
           service: "switch.toggle"
           data:
             entity_id: "switch.bedroom"
    - min_length: 500ms
      max_length: 1000ms
      then:        
       - homeassistant.service:
           service: "switch.toggle"
           data:
             entity_id: "switch.back_porch_lights"