Zigbee outlet module that will distinguish button press from remote activation?

I’ve been buying the Thirdreality smart plugs, which are great. But what they don’t seem to have is the ability to distinguish being activated by button press vs. being activated remotely. I’d like the ability to treat those two cases differently: for instance, if a user turns the module on personally, it might override timeouts set up by a motion detection automation.

So first: can anyone recommend a different module, that can do what I want?

But actually, occurs to me that HA should be able to tell the difference, without help from the module. If HA sent a command to the module, and it changed state, then clearly that was a result of remote activation. But if the module changes state and HA wasn’t involved, then it must have been a person. Can HA do this, currently? Am I missing something?

Hello pgf,
Perhaps think about the automation differently.

Sounds like you have an automation that turns on the plug.
Another automation should be looking at when the plug turns on to enable things like motion, not when the button is pushed to turn it on. Then any time the plug turns on it will react to the motion sequence.

Splitting out a manual vs auto turning on of a device, where technically possible, is a more advanced action and likely unnecessary.

This is a template sensor I use to know what turned on the kitchen light.

- trigger:
    - platform: state
      entity_id: light.lichtkeuken
      to: "on"
  sensor:
    - name: "Keuken Licht On Context"
      unique_id: '018e8402-759b-761b-bf24-272b807826e6'
      state: >
          {% set c_id = trigger.to_state.context.id %}
          {% set c_parent = trigger.to_state.context.parent_id %}
          {% set c_user = trigger.to_state.context.user_id %}
          {% if c_id != none and c_parent == none and c_user == none %}
            physical
          {% elif c_id != none and c_parent == none and c_user != none %}
            dashboard_ui
          {% elif c_id != none and c_parent != none and c_user == none %}
            automation
          {% else %}
            unknown
          {% endif %}

1 Like

I wasn’t clear on my use case.

I have lights over my workbench that come on, via motion, when I pass through the hallway (where the sensor is, and must remain) to get to the shop. They stay on for an hour, which most of the time is far too much – I enter, get something, and leave. But sometimes I actually work at the workbench, and if I’m still there in an hour, the light goes out. At that point I can either walk back to the hallway, to buy another hour, or reach over and turn the light back on with the button on the module. It will come on, but will soon turn off again because of motion inactivity. I’ve tried using the “module-turned-on” event to make things work, that event also happens when motion turns the light on in the first place, and things quickly got very confusing.

@francisp – I have no idea how that works. :slight_smile:

The sensors creates a sensor with 4 states : physical, dashboard_ui, automation, unknown

Physical : someone turned the light on manually
dashboard_ui : someone turned the light on from the dashboard
automation : the light was turned on by an automation (motion sensor)
unknown : should not happen, but you need to have a final if :slight_smile:

So in my light turn of on no occupancy, I have this condition

  condition: 
  - condition: state
    entity_id: sensor.keuken_licht_on_context
    state: 'automation'

So the light does not turn of if someone used the switch manually. (never use the dashboard to switch lights)

1 Like

If all you need is to have lights on or off with timer based on if motion is detected in a room and you have a door then add in a door sensor and use this blueprint to set your thresholds:

I use this with a motion sensor in my bathroom and the sensor on the door so that whilst there is motion detected the light stays on and after 5min of no motion the light is turned off.

Clever. Unfortunately, no door. I could obviously solve my problem with another motion sensor near the workbench. But since there are still some manually controlled lights, and I almost always turn them on, reaching over and pushing the button on the zigbee module for the workbench light isn’t a big deal. It’s just getting my automations to understand what’s happened that’s the tricky part.

Since I don’t have a door to my bedroom between my lounge room and it, this is the solution I have done to have manual control of the bedroom lamps via the streamdeck when I need it and let the motion sensor toggle them when I am walking through.



alias: "Motion/Toggle: Lights"
description: ""
mode: single
triggers:
  - entity_id:
      - binary_sensor.bedroom_motion_sensor_motion
    id: Bedroom Motion Sensor - Last Triggered - Detected
    to: "on"
    trigger: state
  - entity_id:
      - binary_sensor.bedroom_motion_sensor_motion
    id: Bedroom Motion Sensor - Last Triggered - Clear
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 30
    trigger: state
  - entity_id:
      - input_boolean.bedside_lamps
    from: "off"
    to: "on"
    id: Bedside Lamps On
    trigger: state
  - entity_id:
      - input_boolean.bedside_lamps
    from: "on"
    to: "off"
    id: Bedside Lamps Off
    trigger: state
  - entity_id:
      - binary_sensor.kitchen_motion_sensor_motion
    id: Kitchen Motion Sensor - Last Triggered - Detected
    to: "on"
    trigger: state
  - entity_id:
      - binary_sensor.kitchen_motion_sensor_motion
    id: Kitchen Motion Sensor - Last Triggered - Clear
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 45
    trigger: state
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Bedroom Motion Sensor - Last Triggered - Detected
        sequence:
          - data: {}
            target:
              entity_id: input_boolean.bedside_lamps
            action: input_boolean.turn_on
          - target:
              label_id: bedside_lamps
            data:
              brightness_pct: 75
              transition: 600
            action: light.turn_on
      - conditions:
          - condition: trigger
            id:
              - Bedroom Motion Sensor - Last Triggered - Clear
        sequence:
          - target:
              entity_id:
                - input_boolean.bedside_lamps
            data: {}
            action: input_boolean.turn_off
          - target:
              label_id: bedside_lamps
              entity_id: light.bedroom_switch
            data: {}
            action: light.turn_off
      - conditions:
          - condition: trigger
            id:
              - Bedside Lamps On
        sequence:
          - target:
              label_id: bedside_lamps
            data:
              brightness_pct: 50
            action: light.turn_on
      - conditions:
          - condition: trigger
            id:
              - Bedside Lamps Off
        sequence:
          - target:
              label_id: bedside_lamps
            data: {}
            action: light.turn_off
      - conditions:
          - condition: trigger
            id:
              - Kitchen Motion Sensor - Last Triggered - Detected
          - condition: sun
            before: sunrise
            after: sunset
        sequence:
          - metadata: {}
            data: {}
            target:
              entity_id: light.kitchen_switch
            action: light.turn_on
      - conditions:
          - condition: trigger
            id:
              - Kitchen Motion Sensor - Last Triggered - Clear
        sequence:
          - target:
              entity_id:
                - light.kitchen_switch
            data: {}
            action: light.turn_off
1 Like

I’ve had more time to look at your solution, and I understand it now. Well done. I guess the state: “automation” condition remains the same until the next time the light switch is switched to “on”, and then it’s recomputed?

Yes, it only changes when the light is turned on.