Milfra Motion Sensor Light Switch (MFA05)

Got one of the motion sensor light swithes off cloudfree (CloudFree Motion Light Switch - CloudFree) and it’s working well. But, I’m trying to find out how to turn off the LED and not coming up with anything.

It’s also listed at Milfra Motion Sensor Light Switch (MFA05) Configuration for Tasmota

Basically I’d like to be able to turn the light switch on and off, but have the LED remain off (or only come on for a short time). It’s running Tasmota and I tried some of the command line options like LedPower but nothing seemed to work.

Would also love to be able to figure out the actual level of light other than on/off but not sure that’s possible

The Smart life app has an option to turn the LED off.

I also have one of those CloudFree motion switches, but flashed it with ESPHome. Only after doing so did I realize there are two separate LEDs. Just like you see in the Milfra docs, one is green (GPIO16) and the other is blue (GPIO13).

When the relay (GPIO12) is off, each LED is switchable with the green taking priority over blue. However, when you turn on the relay, the green LED is always on regardless of its pin state in software.

1 Like

Where’s the smart life app?

That’s great info! I’m guessing there’s a way to toggle those GPIO’s from the console or something?

Check out Commands - Tasmota

1 Like

Is there a way to toggle the GPIO12 off? Also, I tried all of the Ledstate and Ledpower commands but nothing seems to turn off the Green LED.

Can you show me the config you used for ESPHome?

Thanks!

I’ll post my yaml file when I get home from work.

FYI I was never able to OTA the esphome bin file when the switch had tasmota on it. I had to open it up and flash via UART. There are no pin headers, only solder pads. So, some light soldering may (will) be required.

# https://templates.blakadder.com/cloudfree_SWM1.html
# https://templates.blakadder.com/milfra_MFA05.html

# | GPIO   | Component |
# | ------ | --------- |
# | GPIO0  | button |
# | GPIO5  | motion |
# | GPIO12 | relay |
# | GPIO13 | blue led |
# | GPIO14 | light sensor |
# | GPIO16 | green led |

# GPIO16 boots HIGH which means the green led is ON.
# This is an issue because of the green led takes precendence over the blue led
# To deal with this, GPIO16 must be set LOW after boot which is done using the output component.
# This component defaults to OFF so the user DOES NOT need to use
#    (I) output.turn_off
#     or (II) digitalWrite(16, LOW) after boot




substitutions:
  node_name: cloudfree-motion-light-switch
  friendly_name: CloudFree Motion Light Switch


esphome:
  name: ${node_name}
  build_path: ./build/${node_name}
  comment: CloudFree SWM1 Motion Light Switch
  name_add_mac_suffix: true


esp8266:
  board: esp01_1m


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: ${node_name}_AP
    password: !secret wifi_password
    ap_timeout: 3min


api:
  encryption:
    key: !secret esphome_encryption_key
  reboot_timeout: 0s


captive_portal:

improv_serial:

logger:

ota:


button:
  - platform: restart
    id: restart_button
    name: "${friendly_name} Restart"

  - platform: safe_mode
    id: restart_button_safe_mode
    name: "${friendly_name} Restart (Safe Mode)"


text_sensor:
  - platform: version
    name: "${friendly_name} ESPHome Version"

  - platform: wifi_info
    ip_address:
      name: "${friendly_name} IP Address"
    mac_address:
      name: "${friendly_name} MAC Address"


number:
  - platform: template # time the relay is ON when triggered by motion
    id: motion_delay
    name: ${friendly_name} Motion Delay
    optimistic: true
    restore_value: true
    entity_category: config
    step: 5
    min_value: 15
    max_value: 300
    initial_value: 30
    mode: box
    unit_of_measurement: s

  - platform: template # time the relay is ON when triggered by button
    id: button_delay
    name: ${friendly_name} Button Delay
    optimistic: true
    restore_value: true
    entity_category: config
    step: 5
    min_value: 60
    max_value: 600
    initial_value: 180
    mode: box
    unit_of_measurement: s

  - platform: template # cooldown time when physical button is pressed
    id: motion_cooldown
    name: ${friendly_name} Motion Cooldown
    optimistic: true
    restore_value: true
    entity_category: config
    step: 5
    min_value: 10
    max_value: 300
    initial_value: 60
    mode: box
    unit_of_measurement: s


output:
  - platform: gpio # green LED
    id: green_led
    pin: GPIO16


light:
  - platform: status_led # blue LED
    id: blue_status
    name: ${friendly_name} Blue LED
    pin:
      number: GPIO13
      inverted: true
    effects:
      - strobe:
          name: Fast Flash
          colors:
            - state: true
              duration: 250ms
            - state: false
              duration: 250ms


binary_sensor:
  - platform: gpio # physical button
    id: relay_button
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    on_multi_click:
      - timing: # toggle relay & motion / button timeouts
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: relay
          - if:
              condition:
                - switch.is_on: motion_enabled
              then:
                - script.execute: cooldown
              else:
                if:
                  condition:
                    not:
                      - script.is_running: cooldown
                  then:
                    - script.execute: button_timeout
          - delay: 100ms
          - wait_until:
              condition:
                - not:
                    script.is_running: cooldown
                - not:
                    script.is_running: button_timeout
          - if:
              condition:
                - binary_sensor.is_off: motion
              then:
                - switch.turn_off: relay
      - timing: # enable / disable motion
          - ON for 2s to 5s
        then:
          - script.execute: motion_toggle
      - timing: # software restart
          - ON for 6s to 9s
        then:
          - button.press: restart_button
      - timing: # software restart into safe mode
          - ON for at least 10s
        then:
          - button.press: restart_button_safe_mode

  - platform: gpio # motion sensor
    id: motion
    name: ${friendly_name} Motion
    pin:
      number: GPIO5
      inverted: true
    device_class: motion
    filters:
      - delayed_off: 5s
    on_press:
      - script.stop: motion_timeout
      - if:
          condition:
            - switch.is_on: motion_enabled
          then:
            - switch.turn_on: relay
    on_release:
      - script.execute: motion_timeout

  - platform: gpio # light sensor
    id: daylight
    name: ${friendly_name} Daylight
    pin: GPIO14
    device_class: light
    filters:
      - delayed_on: 5s
      - delayed_off: 5s
    on_press:
      - if:
          condition:
            - switch.is_on: nightlight_enabled
          then:
            - light.turn_off: blue_status
    on_release:
      - if:
          condition:
            - switch.is_on: nightlight_enabled
          then:
            - light.turn_on: blue_status


switch:
  - platform: gpio # relay
    id: relay
    name: ${friendly_name}
    pin: GPIO12

  - platform: template # enable / disable motion
    id: motion_enabled
    name: ${friendly_name} Motion Enabled
    restore_state: true
    optimistic: true
    entity_category: config
    device_class: switch

  - platform: template # enable / disable nightlight
    id: nightlight_enabled
    name: ${friendly_name} Nightlight Enabled
    restore_state: true
    optimistic: true
    entity_category: config
    device_class: switch


script:
  # not in motion sensor on_release because of an issue with on_press not cancelling the delay
  - id: motion_timeout
    mode: restart
    then:
      # subtract 5 for the delayed_off of the motion sensor
      - delay:  !lambda 'return (id(motion_delay).state - 5) * 1000;'
      - if:
          condition:
            - switch.is_on: motion_enabled
          then:
            - switch.turn_off: relay

  - id: motion_toggle
    mode: queued
    then:
      - switch.toggle: motion_enabled
      - if:
          condition:
            - switch.is_off: relay
          then:
            - light.turn_on:
                id: blue_status
                effect: Fast Flash
            - delay: 1600ms
            - light.turn_off: blue_status

  # if mode: restart, this causes motion to not be re-enabled
  - id: cooldown
    mode: single 
    then:
      - switch.turn_off: motion_enabled
      - delay: !lambda 'return id(motion_cooldown).state * 1000;'
      - switch.turn_on: motion_enabled

  - id: button_timeout
    mode: restart
    then:
      - delay: !lambda 'return id(button_delay).state * 1000;'

[EDIT: include yaml file]

5 Likes

Was hoping to be able to post that I’ve resolved this. But what you wrote originally seems to be true. When GPIO12 is ON, the greed LED is always on. I haven’t found any combination of commands that will turn that LED off. Which, is all I really want. Is there anything in Tasmota that can toggle the LED off? Is it some how hard wired? I would be happy just turning the entire LED off and not having it do anything. But changing Switch settings, Button settings. Nothing seems to work.

Here’s my Milfra / CloudFree ESPHome template: coniferhome-esphome/cloudfree-swm1.yaml at 4e83b44c6ff432931c7da7e030a19b06a2d29b23 · peddamat/coniferhome-esphome · GitHub

I concur with rootnegative1.

I probed the circuit board, the Green LED is hard-wired to the relay, so when the relay is on, the Green LED is on.

Additionally, the Green LED has priority over the Blue LED, so if the Blue LED is on and the relay turns on, the switch will turn green.

1 Like

Thanks for the update. That’s pretty much what I was thinking, it must be hardwired. Which is too bad. It’s a great switch and motion detector. But that green LED always being on when the relay is on means I’m only going to be able to put it in certain rooms.

If you’re interested, I’m pretty sure you can fairly easily cut a single trace to prevent this behavior. If I get around to figuring it out I’ll update this thread.

Seems like a very good option! Thanks!

Hi
I now have 3 of the Cloudfree switches running Esphome and they work great. Except I find that the daylight sensor turns off when there is light in the room and therefore no need for the switch to turn on. Has anyone found a way to adjust the sensitivity of this sensor? I tried using Sunrise and Sunset along with the daylight sensor to better determine when to toggle the switch, which has helped. Also added checking for cloud coverage to see of the light is needed but I’m finding the the cloud coverage is mostly 100% when the light is still not needed. Any ideas on how to correct this?

Thanks.
5310

Having the same issue about the light. It would be nice if it would give light levels instead of just on/off for the amount of illumination. I have a few aquara sensors and those give the amount of illumination and it works perfectly to set up automations

Just wanted to drop in and say this works perfectly. Very much appreciate you figuring this out and posting for the community.

This is the only issue I have with these switches. I’ve tried setting the trigger to ‘no light for 5 mins’ and that doesn’t work either. These would be perfect if the light sensitivity was better. So far I’ve found no way around this issue either.

Yeah, I too was hoping that the inbuilt light sensor would give out a light level reading but it seems to just be a “on/off”…

Hey all (especially @rootnegativ1).

I just posted this PR into the esphome devices repo to make sure this example lives on: