Pin is used in multiple places

But why do you need both pulse counter and pulse meter? The pulse meter gives you both liter/min and m3, so what are you doing with the number of pulses (pulse counter).

I also have the problem for days with the error message!
Unfortunately I can’t fix it by adding (allow_other_uses: true)
This gives me a new error message

Bildschirmfoto 2023-12-23 um 16.54.42

Thank you for this, this was the solution for me as well!

Please don’t post photos of text. I think you want

platform: pulse_counter
pin:
  number: 13
  allow_other_uses: true
name: Pulse Counter

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