Xiaomi Vibration Sensor Use Cases

I use plugs with power monitoring for washer and dryer as well.

I tried the vibration sensors for that but that doesn’t worked at all.

I have this - it works, and my automation announces accurately when the washing machine or dryer are finished. However they don’t know if the door has been opened, and if the kids forget to turn off the device, it continues to announce…

I tried to use the vibration sensor to detect the door opening, but coulnd’t get it to work.
(and can’t use a magnetic relay switch, as the door is steel/magnetic!)

You don’t need a door sensor for that…

Create an automation that when power goes above, let’s say, 50 wats, then turns on a second automation.

This second automation is the one you say you already have, the one with the announcement. This one triggers, let’s say, when power has been below 3 watts for more than 2 minutes… When it triggers, its first action is to turn itself off, so it only makes one announcement.

Until the washing machine goes above 50 again, it won’t turn on the announcement automation again…

1 Like

So not using vibration sensor, and because I can’t remember where i got the original, the package I’m using:

#################################################################
#                                                               #
#                     Packages/Appliances                       #
#                                                               #
#################################################################

#################################################################
#                                                               #
#                          Customize                            #
#                                                               #
#################################################################

homeassistant:
  customize:
#    binary_sensor.door_window_sensor_158d0001e73a83:
#      friendly_name: Washing Machine Door
#      icon: mdi:door
    switch.plug_158d0002431039:
      friendly_name: Washing Machine
      initial_state: on
      icon: mdi:washing-machine
    sensor.washing_machine_status:
      icon: mdi:washing-machine
#    binary_sensor.door_window_sensor_158d0001e73bc5:
#      friendly_name: Dryer Door
#      icon: mdi:door
    switch.plug_158d00024333bd:
      friendly_name: Dryer
      initial_state: on
      icon: mdi:tumble-dryer
    sensor.dryer_status:
      icon: mdi:tumble-dryer


#################################################################
#                                                               #
#                            Groups                             #
#                                                               #
#################################################################

group:
  washing_machine:
    name: Washing Machine
    entities:
      - switch.plug_158d0002431039
      - sensor.washing_machine_status
#      - binary_sensor.door_window_sensor_158d0001e73a83

  dryer:
    name: Dryer
    entities:
      - switch.plug_158d00024333bd
      - sensor.dryer_status
#      - binary_sensor.door_window_sensor_158d0001e73bc5



#################################################################
#                                                               #
#                            Inputs                             #
#                                                               #
#################################################################

input_boolean:
  disable_washing_machine_notification:
    name: Disable Washing Machine Notification
    initial: off
    icon: mdi:washing-machine

  disable_dryer_notification:
    name: Disable Dryer Notification
    initial: off
    icon: mdi:tumble-dryer

input_select:
  washing_machine_status:
    name: Washing Machine Status
    options:
      - Idle
      - Running
      - Finishing
      - Clean
    initial: Idle

  dryer_status:
    name: Dryer Status
    options:
      - Idle
      - Running
      - Finishing
      - Clean
    initial: Idle

#################################################################
#                                                               #
#                           Sensors                             #
#                                                               #
#################################################################

sensor:

####################################################
#                                                  #
#                Sensors - Template                #
#                                                  #
####################################################

  - platform: template
    sensors:
## Washing Machine Status
      washing_machine_status:
        value_template: '{{ states.input_select.washing_machine_status.state}}'
        friendly_name: 'Washing Machine Status'
## Washing Machine Power Usage
      washing_machine_power:
        value_template: '{{ states.switch.plug_158d0002431039.attributes.load_power|int }}'
        friendly_name: 'Washing Machine Power'
## Dryer Status
      dryer_status:
        value_template: '{{ states.input_select.dryer_status.state}}'
        friendly_name: 'Dryer Status'
## Dryer Power Usage
      dryer_power:
        value_template: '{{ states.switch.plug_158d00024333bd.attributes.load_power|int }}'
        friendly_name: 'Dryer Power'

#### Lovelace-UI ####

## Washer Power Graph
      washing_machine_load:
        value_template: 'Power: {{ states.switch.plug_158d0002431039.attributes.load_power|int }}'
        friendly_name: 'Washer Power'
        unit_of_measurement: 'W'
## Washer Status
      washer_status:
        value_template: 'Washer: {{ states.input_select.washing_machine_status.state}}'
        friendly_name: 'Washing Machine Status'
## Dryer Power Graph
      dryer_load:
        value_template: 'Power: {{ states.switch.plug_158d00024333bd.attributes.load_power|int }}'
        friendly_name: 'Dryer Power'
        unit_of_measurement: 'W'
## Dryer Status
      clothes_dryer_status:
        value_template: 'Dryer: {{ states.input_select.dryer_status.state}}'
        friendly_name: 'Dryer Status'


 #     washer_door_status:
 #       friendly_name: Door
 #       entity_id: binary_sensor.door_window_sensor_158d0001e73a83
 #       value_template: >-
 #         {% if is_state('binary_sensor.door_window_sensor_158d0001e73a83', 'on') %}
 #           Open
 #         {% elif is_state('binary_sensor.door_window_sensor_158d0001e73a83', 'off') %}
 #           Closed
 #         {% endif %}

 #     dryer_door_status:
 #       friendly_name: Door
 #       entity_id: binary_sensor.door_window_sensor_158d0001e73bc5
 #       value_template: >-
 #         {% if is_state('binary_sensor.door_window_sensor_158d0001e73bc5', 'on') %}
 #           Open
 #         {% elif is_state('binary_sensor.door_window_sensor_158d0001e73bc5', 'off') %}
 #           Closed
 #         {% endif %}



#################################################################
#                                                               #
#                      Automations                              #
#                                                               #
#################################################################



automation:
## When power is detected, and the washing machine is not in
## the Running state, change the status of the washing machine
## to Running.
## The status check will ensure we don't try to put the state
## to Running each time the power level changes, and we're already
## in the Running state.

  - alias: Set washing machine active when power detected
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d0002431039
        value_template: '{{ state.attributes.load_power }}'
        above: 8
        for:
          minutes: 1
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: sensor.washing_machine_status
          state: Idle
        - condition: state
          entity_id: sensor.washing_machine_status
          state: Clean
        - condition: state
          entity_id: sensor.washing_machine_status
          state: Finishing
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.washing_machine_status
          option: Running

## When the power drops, move the state of the washing machine to
## Finishing.

  - alias: Set washing machine finished when power drops
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d0002431039
        value_template: '{{ state.attributes.load_power }}'
        below: 6
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_select.washing_machine_status
          state: Running
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.washing_machine_status
          option: Finishing

## Wait 1 minutes for us to be in the Finishing state before we
## decide the washing machine has finished. This way, if the
## washing machine is in between cycles and the power drops, we
## won't mark the washing machine cycle as finished too early.

  - alias: Set washing machine clean after timeout
    trigger:
      - platform: state
        entity_id: input_select.washing_machine_status
        to: Finishing
        for:
          minutes: 1
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_select.washing_machine_status
          state: Finishing
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.washing_machine_status
          option: Clean

## When we turn off the power, reset the status back to
## idle, so we don't spam people that the washing machine has
## finished, and someone has already emptied it - assumes it is empty.

  - alias: Set washing machine dirty when door opens
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d0002431039
        value_template: '{{ state.attributes.load_power }}'
        below: 3
        for:
          minutes: 1
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: input_select.washing_machine_status
          state: Clean
        - condition: state
          entity_id: input_select.washing_machine_status
          state: Finishing
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.washing_machine_status
          option: Idle

## Washing Machine Alerts
  - alias: Send alert when washing machine is finished
    trigger:
      - platform: state
        entity_id: sensor.washing_machine_status
        to: Clean
        for:
          minutes: 1
      - platform: state
        entity_id: binary_sensor.someone_home
        to: "on"
        for:
          minutes: 2
      - platform: time_pattern
        minutes: 5
    condition:
      condition: and
      conditions:
        - condition: time
          before: '21:00:00'
          after: '08:00:00'
        - condition: state
          entity_id: binary_sensor.someone_home
          state: "on"
        - condition: state
          entity_id: input_select.washing_machine_status
          state: Clean
        - condition: state
          entity_id: input_boolean.disable_washing_machine_notification
          state: 'off'
        - condition: template
          value_template: >
            {% if states.automation.send_alert_when_washing_machine_is_finished.last_triggered is not none %}
              {% if as_timestamp(now()) | int   -  as_timestamp(states.automation.send_alert_when_washing_machine_is_finished.attributes.last_triggered) | int > 1800 %} true {% else %} false
              {% endif %}
            {% else %}
            false
            {% endif %}
    action:
      - service: notify.google_assistant
        data:
          message: 'The washing machine has finished and is ready to be emptied'
      - service: notify.emailjonwork
        data:
          message: 'The washing machine has finished and is ready to be emptied'

## When power is detected, and the dryer is not in
## the Running state, change the status of the dryer
## to Running.
## The status check will ensure we don't try to put the state
## to Running each time the power level changes, and we're already
## in the Running state.

  - alias: Set dryer active when power detected
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d00024333bd
        value_template: '{{ state.attributes.load_power }}'
        above: 10
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: sensor.dryer_status
          state: Idle
        - condition: state
          entity_id: sensor.dryer_status
          state: Clean
        - condition: state
          entity_id: sensor.dryer_status
          state: Finishing
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.dryer_status
          option: Running

## When the power drops, move the state of the dryer to
## Finishing.

  - alias: Set dryer finished when power drops
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d00024333bd
        value_template: '{{ state.attributes.load_power }}'
        below: 6
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_select.dryer_status
          state: Running
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.dryer_status
          option: Finishing

## Wait 1 minutes for us to be in the Finishing state before we
## decide the dryer has finished. This way, if the
## dryer is in between cycles and the power drops, we
## won't mark the dryer cycle as finished too early.

  - alias: Set dryer clean after timeout
    trigger:
      - platform: state
        entity_id: input_select.dryer_status
        to: Finishing
        for:
          minutes: 1
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_select.dryer_status
          state: Finishing
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.dryer_status
          option: Clean

## When we open the dryer door, reset the status back to
## idle, so we don't spam people that the dryer has
## finished, and someone has already emptied it
#
  - alias: Set dryer dirty when door opens
    trigger:
      - platform: numeric_state
        entity_id: sensor.tumbledryer_power_sensor #switch.plug_158d00024333bd
#        value_template: '{{ state.attributes.load_power }}'
        below: 0.2
        for:
          minutes: 1
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: input_select.dryer_status
          state: Clean
        - condition: state
          entity_id: input_select.dryer_status
          state: Finishing
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.dryer_status
          option: Idle

## Dryer Alerts
  - alias: Send alert when dryer is finished
    trigger:
      - platform: state
        entity_id: sensor.dryer_status
        to: Clean
        for:
          minutes: 1
      - platform: state
        entity_id: binary_sensor.someone_home
        to: "on"
        for:
          minutes: 2
      - platform: time_pattern
        minutes: 5
    condition:
      condition: and
      conditions:
        - condition: time
          before: '21:00:00'
          after: '08:00:00'
        - condition: state
          entity_id: binary_sensor.someone_home
          state: "on"
        - condition: state
          entity_id: input_select.dryer_status
          state: Clean
        - condition: state
          entity_id: input_boolean.disable_dryer_notification
          state: 'off'
        - condition: template
          value_template: >
            {% if states.automation.send_alert_when_washing_machine_is_finished.last_triggered is not none %}
              {% if as_timestamp(now()) | int   -  as_timestamp(states.automation.send_alert_when_washing_machine_is_finished.attributes.last_triggered) | int > 1800 %} true {% else %} false
              {% endif %}
            {% else %}
            false
            {% endif %}
    action:
      - service: notify.google_assistant
        data:
          message: 'The dryer has finished and is ready to be emptied'
      - service: notify.emailjonwork
        data:
          message: 'The dryer has finished and is ready to be emptied'

Too long a day to work out how to change it as you suggest…

I really don’t understand why would I do all that for something that can be done with a 10% of that code and less hardware. I really think you overdid it

  - alias: Set washing machine active when power detected
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d0002431039
        value_template: '{{ state.attributes.load_power }}'
        above: 50
    action:
      - service: homeassistant.turn_on
        entity_id: automation.send_alert_when_washing_machine_is_finished


  - alias: Send alert when washing machine is finished
    trigger:
      - platform: numeric_state
        entity_id: switch.plug_158d0002431039
        value_template: '{{ state.attributes.load_power }}'
        below: 6
        for:
          minutes: 1
      - platform: state
        entity_id: binary_sensor.someone_home
        to: on
        for:
          minutes: 2
      - platform: time_pattern
        minutes: 5
    condition:
      condition: and
      conditions:
        - condition: time
          before: '21:00:00'
          after: '08:00:00'
        - condition: numeric_state
          entity_id: sensor.washing_machine_power
          below: 6
          for: '00:01:00'
        - condition: state
          entity_id: binary_sensor.someone_home
          state: on
          for: '00:02:00'
    action:
      - service: notify.google_assistant
        data:
          message: 'The washing machine has finished and is ready to be emptied'
      - service: notify.emailjonwork
        data:
          message: 'The washing machine has finished and is ready to be emptied'
      - wait_template: "{{ state_attr('switch.plug_158d0002431039', 'load_power')|float < 0.5 }}"
      - service: homeassistant.turn_off
        entity_id: automation.send_alert_when_washing_machine_is_finished
3 Likes

Thank you for comforting me everyday in my choice of NodeRed for my automotions ! :smile:

I thought exactly the same, it’s crazy to do that in YAML, yet how easily would that fit in Node Red

I guess it becomes better when you get used to it, but what I dislike about yaml is the number of lines to do so few things… you’ll need to scroll at least on 3 or 4 full screens to have a global picture while this will fit in 15-25 nodes on Node Red that will easily be displayed on one screen.

Thanks Home Assistant to provide so many ways to do things ! :slight_smile:

1 Like

In my defence, I used someone else’s code, and it worked for what I wanted (plus the code does both washing machine and dryer, so twice as many lines…).

In addition, the package also sets up up some graphs which were useful for checking the power values, and sets a status flag for running, idle etc, so your code whilst doing the notification isn’t a direct replacement. (not complaining here btw)

1 Like

never got to the point of installing it, so I dont know what I’m missing.

And as always with HASS, multiple ways to do something…

1 Like

No need to defence sorry… my mistake, you are absolutely right…

If you happen to have some time one day, you might take a few hours to try Node Red out.
It’s very powerfull and has some advantages : it is very grafical, it does what you see, and you see the node values et their timestamp, very usefull to understand how things move in a flow. And as I said you can define complex algorithms and keep a global picture on one single screen where you would have to use 3, 4 or 5 screen is yaml for instance. :slight_smile:

It has also has some inconvenient. For my point of view, the 2 main inconvenients of Node Reds used with HA are :

  • It’s a plugin… one more external ‘layer’
  • Entities used in Node Red flows are not updated when you rename them in Home Assistant for instance… So you better rename all you entities after their integration and not changed them afterwards and don’t forget to do it also on Node Red side which is not really user friendly.

I will personally have to do things in the reverse way and take time to learn about core yaml automotions, especially since Blueprints have been added, so I will be able to take the best form both worlds.

I want to try a vibration sensor to capture the moment that the storm is near and you need to turn off the main switch of my house. I plan to monitor the readings of the sensor attached to the window pane. (When lightning is nearby - the windows vibrate well)

Has anyone done this?

My history_stats sensor won’t count. It stays at 0. I do detect movement. I have the vibration sensor connected through homekit controller. What could the problem be?

Can you post your yaml config?

I’ve got the following in the configuration.yaml.

  • platform: history_stats
    name: Wasmachine Vibrations
    entity_id: binary_sensor.vibration_sensor
    state: ‘vibrate’
    type: ‘count’
    end: ‘{{ now() }}’
    duration: 600

I’ve made a test lovelace panel. See picture. It detects when there is movement, but it doesn’t count up.

I’ve found the solution. I had to change ‘state’ to ‘on’ and not ‘vibrate’. It seems to work now.

Can you share your configuration? My vibration sensor is laying around doing nothing…

I made this automatisation:
alias: Wasmachine einde
description: Melding als wasmachine gedaan is
trigger:

  • platform: numeric_state
    entity_id: sensor.wasmachine_vibraties
    above: ‘4’
    condition:
  • condition: state
    entity_id: input_boolean.wasmachine
    state: ‘off’
    action:
  • service: input_boolean.turn_on
    target:
    entity_id: input_boolean.wasmachine
  • delay:
    hours: 1
    minutes: 50
    seconds: 0
    milliseconds: 0
  • service: notify.mobile_app_gsm_james
    data:
    message: Wasmachine is klaar!
    title: Wasmachine is klaar
  • service: tts.google_translate_say
    data:
    entity_id: media_player.nest_speaker_woonkamer
    message: Wasmachine is klaar
    language: nl-BE
  • service: input_boolean.turn_off
    target:
    entity_id: input_boolean.wasmachine
    mode: single

I also made this sensor:
sensor:

  • platform: history_stats
    name: wasmachine vibraties
    entity_id: binary_sensor.vibration_sensor
    state: ‘on’
    type: ‘count’
    end: ‘{{ now() }}’
    duration: 00:30

I’m a real amateur, so if you find anything to make it better, let me know. The problem with this is that it doesn’t recognize the difference between a hot wash and a was at 30°. A hot was takes much longer, so I have to take the time of the longest wash.

Would like to know your configuration too if possible.