Wyze Sense Motion and Contact Sensor Integration via IFTTT handled through Node Red

With Wyze recently coming out with their Wyze Sense motion and contact sensors I decided to incorporate these into my Home Assistant setup to create my own home security system (among other things). I’ve done this by creating 4 individual IFTTT applets, adding hidden input_booleans for each sensor, creating HA sensors that follow the value of the input_booleans, and then tracking IFTTT webhooks through Node-RED. Here’s how I went about it:

  1. Setup devices in the Wyze app, naming them accordingly (i.e. kitchen_sensor) so they can flow over to HA
  2. In IFTTT, create a new applet, selecting Wyze Motion Sensor or Contact Sensor as the trigger
  3. For action, choose ‘Webhooks’ make a web request, setting up your URL and other fields as shown below.
    Note: I had to disconnect and reconnect IFTTT to get my custom webhook URL as well as remove ‘:8123’ from it to get it to work.

  1. Setup your input booleans
  kitchen_sensor:
    name: Kitchen Sensor
    icon: mdi:motion-sensor
  back_door_sensor:
    name: Back Door Sensor
    icon: mdi:door
  1. Create your template sensors.
- platform: template
  sensors:
    kitchen_sensor:
      friendly_name: "Kitchen Sensor"
      value_template: >-
        {% if is_state('input_boolean.kitchen_sensor', 'on') %}
          detected
        {% else %}
          clear
        {% endif %}
      entity_picture_template: >-
        {% if is_state('input_boolean.kitchen_sensor', 'on') %}
          /local/icons/motion.png
        {% else %}
          /local/icons/clear.png
        {% endif %}
    back_door_sensor:
      friendly_name: "Back Door Sensor"
      value_template: >-
        {% if is_state('input_boolean.back_door_sensor', 'on') %}
          detected
        {% else %}
          clear
        {% endif %}
      entity_picture_template: >-
        {% if is_state('input_boolean.back_door_sensor', 'on') %}
          /local/icons/motion.png
        {% else %}
          /local/icons/clear.png
        {% endif %}
  1. In Node Red, setup the following nodes: ‘events: all’, ‘switch’, and ‘call service’ as shown below. This receives the IFTTT webhook, ensures it’s a motion_sensor or contact_sensor (and allows us to expand off of the webhooks receiver later on), and then updates the associated input_boolean for the device triggered.


NR2

An Done! Here’s the final result in HA:

I hope you all find this as useful as I do. I just ordered more contact sensors and motion sensors for Wyze this morning. In all, my home security system will consist of 2 cameras, 12 contact sensors, and 5 motion sensors, with all of that only running me ~$150 from Wyze including shipping.

Also, in case you like the sensor images, here they are as well:
clear motion

3 Likes

Thank you for this write up!

What kind of delay do you have on the time the sensors catch motion and an event can be fired in HA?

Very little at all. The sensors immediately send to ifttt so actions like the light turning on are almost immediate.

1 Like

I didnt end up using node red but this helped me thanks! i used these images for doors. only 1-2 second response

dooropen doorclosed

3 Likes

How did you go about doing this with out node red? Keep in mind I’m just getting started with HA, your response could go right over my head. If you could share your code and point me in the right direction I would appreciate it. I’m not much of a coder…but i’m really good at copy-paste-edit lol!!!

Edit: I got it figured out!!!

1 Like

Can you share how you did it?

1 Like

sorry it took me a minute. but its basically the same except the json data in the webhook from ifttt. i use it to turn on and off the input booleans made from the code above

1 Like

It was easier than expected. I created a boolean, and have a webhook to trigger a automation when the sensor opens and another webhook and automation to switch it back off when the sensor closes. Much simpler than what described here but it works.

2 Likes

I did something even simpler. I just added a literal json message: motion and message: clear in the body of my webhooks. I have a switch node, with node red, to check if the payload (msg.payload.event.message) is either set to “motion” or “clear”.

I may set it up with an input boolean and automation, but I’m pretty happy with my simple solution.

Does the template sensors go in the yaml file? im trying to do this in HA not NodeRed

Yes, in your configuration.yaml file.

If you’re trying to do this outside of Node RED I think this is how the automation would look. It passes as a valid configuration but I have not tested it.

- alias: IFTTT Received
  initial_state: 'on'
  hide_entity: true
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      trigger_type: motion_sensor
      trigger_type: contact_sensor
  action:
    service_template: >
      {% if trigger.event.data.trigger_status == "on" %}
      homeassistant.turn_on
      {% elif trigger.event.data.trigger_status == "off" %}
      homeassistant.turn_off
      {% endif %}
    data_template:
      entity_id: input_boolean.{{trigger.event.data.trigger_name}}

Getting this error. I do have a “Sensors.yaml” It doesnt go in there?

Error loading /config/configuration.yaml: mapping values are not allowed here
in “/config/configuration.yaml”, line 153, column 10

Yes, if you have a sensors.yaml file you’ll want to place them in it vice the configuration file.

You see what I am doing wrong? Line 152 is… sensor: !include sensor.yaml

image

image

Ok. So you mentioned template sensors originally. Those go in the sensors.yaml file for you since you have it setup that way.

The automation should go in your automations.yaml file, not your sensors file.

So template sensor is nothing more than a storage spot for the value of a different sensor?

It is a template that fills in data depending on what it was fed, so you can write it once, and have it work for say, 5 different door sensors.

@hoffdad Thanks for this. I did all the automation in HA, and what you posted worked great!

2 Likes

@Bunnywinkles I am trying to do same automation all in HA, but can’t seem to trigger it. I know IFTTT applet is running and posting data to the webhook. But HA automation never triggers. Do you mind posting your code for automation?

- alias: IFTTT Received
  initial_state: 'on'
  hide_entity: true
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      trigger_type: contact_sensor
  action:
    service_template: '{% if trigger.event.data.trigger_status == "on" %} homeassistant.turn_on
      {% elif trigger.event.data.trigger_status == "off" %} homeassistant.turn_off
      {% endif %}

      '
    data_template:
      entity_id: input_boolean.{{trigger.event.data.trigger_name}}
  id: d36912ecb4cf4836a31761c8912206ad

I can’t get the service node working like you did? I get

Error call service, home assistant api error. Error Message: Service not found.

on the

turn_{{payload.event.trigger_status}}

line. (The entity ID line works fine however?)

I verified that IFTTT is sending the right trigger_status. Any ideas? What version is your NodeRed?

Thanks, Bob