Temperature sensor on pipe to monitor shower use

If you are talking about your discord link, it leads to nothing (and I am a member of the esphome discord).

Rightā€¦ Hmmā€¦

Well I used the ā€œcopy link to messageā€ Discord feature and just double checked it is correct. So not sure how else to do it.

Seems to work for me.

Searching Discord for ā€œDelta sensorā€ will also bring it upā€¦

I have manage to solve my problem with a helper and two automations.
First of all I create a input_number sensor.

{{ states('input_number.attic_shower_max_temperature') }}

When temperature is rising the following automation is running, sets the bathroom sensor to occupied, plays a TTS notification and some bathrooom music with Alexa.

alias: Bathroom is occupied (ON)
description: When pipe's temperature above 25Ā°C turn on occupancy switch
trigger:
  - platform: numeric_state
    entity_id: sensor.attic_hot_water_pipe
    above: 25
condition:
  - condition: state
    entity_id: input_boolean.attic_shower_is_occupied
    state: "off"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.attic_shower_is_occupied
  - service: persistent_notification.create
    data:
      title: INFORMATION
      message: |
        Someone has just started to have a shower at {{ states('sensor.time') }}.
  - service: notify.mobile_app_sm_g980f
    data:
      title: INFORMATION
      message: Someone is having a shower...
  - if:
      - condition: state
        entity_id: group.attic_wc
        state: "on"
    then:
      - service: media_player.volume_set
        data:
          volume_level: 1
        target:
          entity_id: media_player.bathroom
      - service: notify.alexa_media
        data:
          target:
            - media_player.bathroom
          data:
            type: tts
          message: >-
            Hmmm. I am sensing that someone is having a shower...Here are some
            songs to sing in the shower!
        alias: "Notifications: Send a notification with alexa_media (bathroom)"
      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
      - service: media_player.select_source
        data:
          source: Bathroom
        target:
          entity_id: media_player.spotify_makis_solomos
      - service: media_player.shuffle_set
        data:
          shuffle: true
        target:
          entity_id: media_player.bathroom
      - service: media_player.play_media
        data:
          media_content_type: playlist
          media_content_id: >-
            https://open.spotify.com/playlist/37i9dQZF1DWSqmBTGDYngZ?si=d31f0e30a8f14ede
        target:
          entity_id: media_player.spotify_makis_solomos
mode: single

At the same time, another automation is running which saves pipeā€™s temperature to the helper.

alias: Bathroom is occupied save temperature to helper
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ states('sensor.attic_hot_water_pipe') >
      states('input_number.attic_shower_max_temperature')  }}
condition: []
action:
  - service: input_number.set_value
    data:
      value: "{{ states('sensor.attic_hot_water_pipe') }}"
    target:
      entity_id: input_number.attic_shower_max_temperature
mode: single

Finally, a final automation checks the temperature and if is falling it consider that the shower is completed:

alias: Bathroom is occupied (OFF)
description: ""
trigger:
  - platform: time_pattern
    minutes: /15
condition:
  - condition: state
    entity_id: input_boolean.attic_shower_is_occupied
    state: "on"
  - condition: template
    value_template: >-
      {{ ((states('sensor.attic_hot_water_pipe') | float -
      states('input_number.attic_shower_max_temperature') | float) *-1) > 3  }}
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.attic_shower_is_occupied
  - service: persistent_notification.create
    data:
      message: |
        Shower is completed {{ states('sensor.time') }}.
      title: INFORMATION
  - service: media_player.media_stop
    data: {}
    target:
      entity_id: media_player.bathroom
mode: single

It works flawlessly!!!

(please note that I had to reset the max. temperature helper so it will run again next day)

alias: Bathroom is occupied reset max. temperature
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.attic_hot_water_pipe
    below: 20
condition:
  - condition: state
    entity_id: input_boolean.attic_shower_is_occupied
    state: "off"
action:
  - service: input_number.set_value
    data:
      value: 21
    target:
      entity_id: input_number.attic_shower_max_temperature
mode: single

1 Like

Why isnā€™t this the trigger?
If this is the trigger then it will trigger immediately as the temperature drops when shower is occupied, not sure I understand why you need to wait for 15 minutes

Because using a numeric state trigger doesnā€™t work always.
If it pass through the threshold it wonā€™t trigger untill it goes up and down againā€¦

I agree that this is the right trigger to fire but I couldnā€™t make it to work.
It didnā€™t fire always with (pipeā€™s temperature - max. temperature) < 3

And If I change the row of sensors e.g. (max - pipe) will also trigger when temperature rises ā€¦ ** see above automation. (because it will give a negative number which is < 3)

So it will switch off the occupancy sensor before it starts ā€¦

Hope I can make myself clear here ā€¦

But why donā€™t you replicate it? ā€¦See yourself the barries that make me choose the time patern trigger instead.

Noā€¦ as a template trigger, just as your condition.
I have several template triggers not specifically like this but they all work fine.

Hi,
I think I would not stick to these static temperature values. I think a more universal way would be (I believe @Mahko_Mahko mentioned that) to just use the temperature gradient / difference over time.
Of course it depends on how you define the window size for your samples.

But the idea is:

  • any temperature rise (no matter which the ā€œstarting temperatureā€ was) will indicate that someone is showering (or anything else that uses warm water).
  • any temperature drop indicates, that warm water usage has been stopped.

So the logic would be (pseudocode):

delta_T = new_sample - old_sample
if delta_T > threshold1: warm_water_use = true
else if delta_T < threshold2: warm_water_use = false

And because someone might take a break while showering (maybe because his/her hair conditioner needs some time) your automation trigger to determine if the shower is really in use or not could observe the duration of how long warm_water_use is true or false.
Something like:

if warm_water_use is true for > delay1: shower_occupied = true
else if warm_water_use is false for > delay2: shower_occupied = false

You only have to define (or evaluate) a reasonable sampling time, the thresholds to determine if warm water is used or not, and the delays to say if the shower is really occupied or not.

This would be universal and flexible.

Greetings!

This is exactly what I suggested in post 7. Use derivative, trend or statistics sensor to know where the data is heading.
But by some reason he uses input number and automations. :man_shrugging:

Sry, I have missed that one :sweat_smile: !
But nice to know that we share a basically same idea :slight_smile: .

Can we please have some real code for ESP ???

because maybe HE is not that expert user like you ā€¦ :slight_smile:
and maybe YOU should read more carefully. :wink:
Please read my post #13
Trend and derivative sensors didnā€™t work for me .

The only thing you said was:

I didnā€™t reply to it before since it looked like an excuse.

1 If your sensor is ESP based then set the update interval.
2 if the sensor does not update frequently enough for a derivative sensor then why would work creating a manual derivative sensor?
3 if your automation triggers every 15 minutes then how can speed be an issue at all?
4 your automation:

alias: Bathroom is occupied save temperature to helper
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ states('sensor.attic_hot_water_pipe') >
      states('input_number.attic_shower_max_temperature')  }}
condition: []
action:
  - service: input_number.set_value
    data:
      value: "{{ states('sensor.attic_hot_water_pipe') }}"
    target:
      entity_id: input_number.attic_shower_max_temperature
mode: single

Triggers in the exact same rate as a derivative, trend or statistics sensor because itā€™s based on the same sensor updating.

Not sure exactly how these sensors did not work for you since they are based on the same entity.
The only difference is that my suggestion was to trigger on a drop in this sensor of a certain degree. I canā€™t answer on what that degree is because I donā€™t have something similar.

My answer on you suggestion was:

Humidity sensor is not an option. Of course I already have one, but it is not always accurate as I live at an island and the humidity is problem ā€¦ Sometimes humidity at the bathroom is too high even though nobody is using the shower! I use it among with trend and derivative sensors but not always accurate in my situation.

I have never talked about a humidity sensor.