Turn ON Side Lamps base who's in bed

Want to have my Side bed lights come on base on who in bed

Shopping List


https://www.itead.cc/sonoff-wifi-wireless-switch.html

Flash the Sonoff with Tasmota

wire one to the RX and the other to TX of the sonoff

set the the SwitchMode 2
Turn on the SwitchTopic 1

Check to see if I stand on then do I see any thing

imimage|418x234 age

place under the mattress NOT to close to the side and about where you bum is ok

binarysensor.yaml

#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "In bed her side"
    state_topic: "cmnd/bed/POWER2"
    qos: 1
    retain: true
    device_class: motion 
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "In bed his side"
    state_topic: "cmnd/bed/POWER3"
    qos: 1
    retain: true
    device_class: motion
#=======================================================================
#
#=======================================================================  

light.yaml

#=======================================================================
#
#=======================================================================
  - platform: mqtt
    entity_id: "Bedroom"
    name: "Master Bedroom"
    state_topic: "stat/MasterLight/POWER"
    command_topic: "cmnd/MasterLight/POWER1"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0
    retain: true
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Her Side"
    state_topic: "stat/herSide/POWER"
    command_topic: "cmnd/herSide/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0
    retain: true
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "His Side"
    state_topic: "stat/hisSide/POWER"
    command_topic: "cmnd/hisSide/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0
    retain: true
#=======================================================================
#
#=======================================================================

also need to see when we are pressing the HOLD
so in sensor.yaml

#=======================================================================
  - platform: mqtt
    name: "herSide Light"
    state_topic: "cmnd/herSide/POWER1"
    qos: 1
    expire_after: "1"
    retain: true
#=======================================================================
  - platform: mqtt
    name: "hisSide Light"
    state_topic: "cmnd/hisSide/POWER1"
    qos: 1
    expire_after: "1"
    retain: true
#=======================================================================
  - platform: mqtt
    name: "master Light"
    state_topic: "cmnd/MasterLight/POWER1"
    qos: 1
    expire_after: "1"
    retain: true

note the “expire_after:” forget what happen after 1 sec

now the FUN part

#=======================================================================
#
#=======================================================================
- id: 'hold Master light off off'
  alias: hold Master light off off
  initial_state: true
  trigger:
  - entity_id: sensor.master_light
    platform: state
    to: 'HOLD'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.in_bed_his_side
        state: 'off'
      - condition: state
        entity_id: binary_sensor.in_bed_her_side
        state: 'off'
  action:
  - data:
      entity_id: light.her_side , light.his_side 
    service: light.toggle
  - data:
      entity_id: input_boolean.going_to_bed
    service: input_boolean.turn_on

#=======================================================================
#
#=======================================================================
- id: 'hold Master light on off'
  alias: hold Master light on off
  initial_state: true
  trigger:
  - entity_id: sensor.master_light
    platform: state
    to: 'HOLD'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.in_bed_his_side
        state: 'on'
      - condition: state
        entity_id: binary_sensor.in_bed_her_side
        state: 'off'
  action:
  - data:
      entity_id: light.her_side 
    service: light.toggle
  - data:
      entity_id: input_boolean.going_to_bed
    service: input_boolean.turn_on

#=======================================================================
#
#=======================================================================
- id: 'hold Master light off on'
  alias: hold Master light off on
  initial_state: true
  trigger:
  - entity_id: sensor.master_light
    platform: state
    to: 'HOLD'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.in_bed_his_side
        state: 'off'
      - condition: state
        entity_id: binary_sensor.in_bed_her_side
        state: 'on'
  action:
  - data:
      entity_id: light.his_side
    service: light.toggle
  - data:
      entity_id: input_boolean.going_to_bed
    service: input_boolean.turn_on

the lovelace look

image

its card

cards:
  - entities:
      - entity: binary_sensor.in_bed_her_side
        icon: 'mdi:bed-empty'
        name: Debbie
      - entity: binary_sensor.in_bed_his_side
        icon: 'mdi:bed-empty'
        name: StePhan
    title: Master Bedroom
    type: glance
  - cards:
      - entity: light.her_side
        tap_action:
          action: toggle
        type: entity-button
      - entity: light.master_bedroom
        hold_action:
          action: toggle
        icon: 'mdi:ceiling-light'
        name: light
        tap_action:
          action: toggle
        type: entity-button
      - entity: light.his_side
        tap_action:
          action: toggle
        type: entity-button
    type: horizontal-stack
  - entities:
      - entity: binary_sensor.in_bed_his_side
        name: StePhan
      - entity: binary_sensor.in_bed_her_side
        name: Debbie
    hours_to_show: 48
    title: ''
    type: history-graph
type: 'custom:vertical-stack-in-card'
4 Likes

Nice! I did something really similar today with two pressure mats and two z-wave contact sensors except I’m using them to prevent the bedside lamp from turning off if either my husband or I is bed and the motion sensor has stopped detecting motion.

@myle If you don"t mind sharing your schematics. Do you have your Sonoff connected to power? I imagine that you are using the 9 volts battery that comes with the pressure mat to provide power to the mat and mains for the sonoff.
Thanks for sharing, I really like it!

Yes its connect to powder the 9v battlery only there for the sound
the mat is connected to gnd and the RX for one side and TX for the other side

Just to clarify this…

How many mats do you need for two people? I assume one for each side so a total of two mats?

Each mat then has two wires coming out of the mat going to the controller?

And you only use one sonoff so that means that one mat connects between ground and the RX pin and then the second mat connects to ground and the TX pin on the same sonoff?

And the mats themselves aren’t powered by anything? It’s just the sonoff is powered from mains?

And lastly, now that you’ve used this for the last 9 months how is the mat holding up? is it still working like it did when you first installed it?

I have 2 mats 1 sonoff

1 mat to RX and GND
other
mat to tx and GND

1 Like