Remembering device states from ifttt

So I’ve spent some time today settling up HA and I’m impressed. Seems exceptionally powerful when compared to say ST.

I did integrate SmartThings as I wanted to bring over my alarm system which doesn’t have a HA integration and all the sensors etc can be seen no bother. The alarm state (armed/disarmed/triggered) isn’t being exposed however.

Now I have seen I can send a webhook request from IFTTT that can be worked into HA if the alarmis armed for example but can I get HA to remember this state somehow?

I’m thinking if it can then I can create further routines in HA dependent on the last state received by the IFTTT webhook?

Any ideas welcomed :+1:

I use Node Red for this. Below is a flow that you can import with HTTP endponits. They control an “input boolean” which is created in Home Assistant. The input boolean is the Smarrthings equivalent of a virtual switch. You can make the input boolean by just going to configuration, helpers, add helper, and then select “toggle”. Type a name and then that entity will be controllable in Node Red.

NR http

[{"id":"fd7b6fd07baabc93","type":"http in","z":"115a2d09.b31883","name":"Turn On","url":"/endpoint/iftttturnon87889","method":"post","upload":false,"swaggerDoc":"","x":120,"y":2780,"wires":[["90948479876a50fa","01de9208fd326aa7"]]},{"id":"90948479876a50fa","type":"template","z":"115a2d09.b31883","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>Connection Message Received</h1>\n    </body>\n</html>","x":330,"y":2860,"wires":[["48d478416c0b42ab"]]},{"id":"48d478416c0b42ab","type":"http response","z":"115a2d09.b31883","name":"","statusCode":"","headers":{},"x":510,"y":2860,"wires":[]},{"id":"01de9208fd326aa7","type":"api-call-service","z":"115a2d09.b31883","name":"Turn on Boolean","server":"ae531ce.a39906","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.something","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":420,"y":2780,"wires":[[]]},{"id":"b01afc467ed97250","type":"api-call-service","z":"115a2d09.b31883","name":"Turn off Boolean","server":"ae531ce.a39906","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.something","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":430,"y":2920,"wires":[[]]},{"id":"bb5e2713fc622e1a","type":"http in","z":"115a2d09.b31883","name":"Turn Off","url":"/endpoint/iftttleave788736","method":"post","upload":false,"swaggerDoc":"","x":110,"y":2920,"wires":[["90948479876a50fa","b01afc467ed97250"]]},{"id":"ae531ce.a39906","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Then on the IFTTT side you setup two actions to send the webhooks to Node Red

IFTTT settings

1 Like

Interesting, that could work. My only reservation is that I’m kludging already by combining HA, Smartthings and IFTTT so adding in NodeRed is another thing that could go wrong :wink:

I’ll keep digging :+1:

Sure, that is a lot of moving parts. I did have that setup running for awhile though and honestly the week link is Smartthings being a cloud based system. I ended up getting zigbee and zwave sticks and totally getting off Smartthings, but it depends on what you’re using. If your alarm system works well with it and doesn’t integrate easily to anything else I can see continuing to use it.

Node Red is an official add-on for Home Assistant and many use it seamlessly with it for automations, etc. I kind of think of them as one in the same honestly.

I know you can setup Home Assistant directly to get the webhook from IFTTT though I just haven’t done it. I tried and it seemed fussy and complex to get it working, and I just found the visual setup of Node Red to be easier for this. Try looking at this documentation on how to set it up -

Maybe someone else can chime in on using Home Assistant directly with IFTTT here.

1 Like

Fair points. My preference would be zwave for the alarm but it is secured so that’s not directly possible hence the ST integration.

I guess it’s one of those set and forget (alarm pun) sort of things so ill certainly take a look.

Thanks for the help :grinning:

Glad I could help. Whether you use Node Red or get the IFTTT integration working in Home Assistant directly (looks like you just have to format JSON properly) I think the key to keeping track of the state will be tying it to an input boolean that will be “on” or “off” depending on the webhook received. You can even make an “input select” called “alarm” with options like “armed” and “disarmed”, and have that update based on webhooks received from IFTTT. I have an input select for “modes” which has home, night, and away like Smartthings modes did, and that “mode” status shows up right at the top of my lovelace dashboard

Mode

Just to tie this off, I now have this working! In case anyone is interested, here’s what I did…

First up, I create a boolean helper and just called it “Alarm Armed”. This has two states of off being disarmed and on being armed.

Next, I added the IFTTT integration which gave me the webhook URL. This looks like this if you use Nabu Casa:

https://hooks.nabu.casa/ReallyLongString

Make a note of this as you will need it later. I now need to create a handler for the webhook. After a bit of hunting about and testing, I found something simple and added the following into my automations.yaml file:

- alias: IFTTT webhook handler  
  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 }}'

Save the file and then restart HA. The nice thing I found about this handler was that it could be used for multiple webhook requests for IFTTT so I didn’t have to write a new handler for each request I sent.

I then headed over to IFTTT and created an applet that would fire when the alarm was armed. I set the fields as:

URL: My webhook URL I created above
Method: POST
Content-Type: application/json
Additional Headers: Not required for me

For the body I now just need to define the json I was sending to the handler. So to tell HA the alarm had been armed, I send:

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

The input_boolean.alarm_armed is the name I gave to my Boolean helper and this request simply switches it on.

I then created a second IFTTT applet and sent input_boolean.turn_off instead of turn_on to toggle the helper off.

Now of course I can create automation based on the Boolean state.

Thanks go to Tim for the idea on this, works like a charm!

1 Like