Withings sleep help

I have connected my two Withings sleep to HA via IFTTT, I can send commands to HA via IFTTT. But I´m not sure what would be the best way to get two sensors, one when I´m in bed and the other one when my girlfriend is in bed. Maybe someone have done this already so I don´t need to invent something here or could point me to the best way to do this?

1 Like

I am using one of mine to turn lights off when I go to bed.
Instead of turning the lights off, why not have two input_boolean one for you and one for your girlfriend. IFTTT turn’s on / off the input_boolean depending on if your are in bed or not?

Then other automation’s could use the input_boolean state as a condition.

My HA part:

#######################################
#                                     #
# Recieve IFTTT.com message           #
#                                     #
#######################################

- alias: Ifttt_webhook
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'

What’s in the body of the message IFTTT sends.

{ "action": "call_service", "service": "light.turn_off", "entity_id": "group.alllights" }

Perhaps try something like this for yours

{ "action": "call_service", "service": "homeassistant.turn_on", "entity_id": "input_boolean.Klangen82Bed" }

{ "action": "call_service", "service": "homeassistant.turn_off", "entity_id": "input_boolean.Klangen82Bed" }

Another two separate ones for your girlfriend.

{ "action": "call_service", "service": "homeassistant.turn_on", "entity_id": "input_boolean.GirlFriendBed" }

{ "action": "call_service", "service": "homeassistant.turn_off", "entity_id": "input_boolean.GirlFriendBed" }

Don’t forget to set your input_boolean in your HA Config

input_boolean:        
  Klangen82Bed:
  GirlFriendBed:
2 Likes

Thanks, this is good suggestion. I use Hassio and not sure how to convert your automation into the right format:/ Do you know how to?

automations.yaml

- alias: Ifttt_webhook
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'

configuration.yaml

input_boolean:        
  Klangen82Bed:
  GirlFriendBed:

Does that help?

Have a look at my GitHub if it helps you to understand better.
Look in configuration.yaml near the bottom, I have a few input_boolean setup. You can also see how to add an icon to an input_boolean

In automations.yaml scroll down to line 425, you can see the bit that recieves the IFTTT message.

If you wanted to turn all of your lights off at 22:45 only if you are both in bed, you could put this in as an automation.

automations.yaml

#Turn all lights off, only if both in bed
- alias: "LightsOoutBothInBed"
  trigger:
    platform: time
    at: '22:45:00'
  condition:
    - condition: state
      entity_id: input_boolean.Klangen82Bed
      state: 'on'
    - condition: state
      entity_id: input_boolean.GirlFriendBed
      state: 'on'
  action:
    - service: homeassistant.turn_off
      entity_id: group.alllights
2 Likes

Thanks guys! As I use Hassio and was thinking the automatons editor as the only way to add automatons. I struggle a bit but den I added a automations_old.yaml to the config folder and then added this code to configuration.yaml

automation old: !include automations_old.yaml

Thanks for the help again!

If
automation old: !include automations_old.yaml
Doesn’t work try the following
automation: !include automations_old.yaml

Glad I could help you and point you in the right direction.

Wills106,

1.st, many many thanks for your suggestion,
I like to implement the same automation, with my bed sensor.

2.nd, I’ve tested the implementation without success…
I have some questions/confirmations for you:

  • The URL, on IFTTT applet must be with SSL (https),
    I’ve tried simple http and Raspberry give error 405…
    At the same time I didn’t see SSL configured enabled
    in your configuration.yaml on GitHub…

  • The URL, on IFTTT applet, have the path to
    ‘/api/webhook/randomnumbers’
    What is this path for?

  • For IFTTT message I need two different message, one for enable the
    binary_sensor and one to disable (home assistant.turn_on/homeassistant.turn_off) ?
    I’s not enough only one…

Please, do you can share some more details about your implementation

Tthanks in advance for your precious suggestion !

Some update after test and investigation:

  • The URL must be the address given by HA with IFTTT plugin installation
    no more error on execution of IFTTT applet.

  • The URL contain the complete path for send IFTTT message

  • Yes, need two different applets,
    one put input_boolean (in bed) to ON (homeassistant.turn_on)
    the second reset this bit (out from bed) to OFF (homeassistant.turn_off)

Anyway, the implementation still doesn’t work…
My input_boolean never goes to TRUE state.

How I can check the IFTTT message raspberry side,
the log is not helpful !

To get this to work you need to first get your HA accessible from the internet:

When you are done with this you will have a https://someting.something that are your access to the HA.

After this you need to add a input boolean that you can trigger from IFTTT in your configuration.yaml, should look something like this:

input_boolean:
  personx_bed:
    name: PersonX In Bed?

A automation need to be created then I made a file called automations_old.yaml in the configuration folder, you need to include this in the configuration.yaml and to to this then add this line:

automation old: !include automations_old.yaml

Then add this to the automations_old.yaml:

- alias: Ifttt_webhook
  trigger:
    platform: event
    event_type: ifttt_webhook_received
    event_data:
      action: call_service
  action:
    service_template: '{{ trigger.event.data.service }}'
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'

Then you of course need to setup IFTTT to work with your HA and you simply press configuration>integrations>IFTTT and follow the instructions

Now it´s time to setup the IFTTT so send event to your HA so choose the applet from Withings Sleep that generate a event when you get out of bed and then make a webhook request. Below is the action to turn off the input boolean and you need to make one for turning it on (get into bed) as well, then just simply change “off” to “on”.

URL = to use is https://something.someting/api/webhook/tooken where https://something.tomething is your HA dns name and tooken is the one you got when you setup the IFTTT under the integration part.

Method = POST

Content Type (optional) = application/json

Body = { "action": "call_service", "service": "homeassistant.turn_off", "entity_id": "input_boolean.personx_bed" }

Hope that this helps you get it to work.

@Klangen82,

yes, every think already done as your suggestion but still doesn’t work… :sob:

Workaround two night and finally I find the solution, change the body of IFTTT message to:

{“action”:“call_service”,“service”:“input_boolean.turn_on”,“entity_id”:“input_boolean.carlo_bed”}
on 1.st applet to switch my flag on, and
{“action”:“call_service”,“service”:“input_boolean.turn_off”,“entity_id”:“input_boolean.carlo_bed”}
on 2.nd applet when leave bed and reset the flag.

moreover, I’ve configured a binary_sensor to check the status of signal on web gui,
(without the switch presence):

binary_sensor:

  • platform: template
    sensors:
    bed_presence:
    friendly_name: ‘Carlo on bed’
    device_class: vibration
    value_template: “{{ states.input_boolean.carlo_bed.state == ‘on’ }}”
    entity_id: input_boolean.carlo_bed

Now work like a charm, thanks for your help !

Per now (HA 100.x.x) there are a origin Home Assistant integration for Withings Health (without detour over IFTTT or other services) in place ->

The sleep sensor is not working for me. Scale parts work, but the withings sleep component throws errors.

1 Like