Setup an On/Off IFTTT switch?

I’m pretty new to Home Assistant, and I want to create an on/off switch that would trigger one IFTTT action for On, and another IFTTT action when switched Off.

I’ve managed to setup a few that trigger single IFTTT actions with the ACTIVATE button/text

script:
        lounge_light_dimmed:
            sequence:
              - service: ifttt.trigger
                data: {"event":"lounge_dimmed_50"}

But not sure how to create an on/off switch to trigger two different IFTTT actions :thinking:

build a input boolean and monitor its on/off states. Input boolean is a fancy name for ‘your own on/off switch’. Build an automation that triggers off “on”, and an automation that triggers off ‘off’. That’s one way you could do it. There are so many ways you can do this. I would try that first and see how fast it is. If it’s slow, I’d investigate other ways.

Thanks, I don’t really know where to start, but I’ll look at that.

Something like:

input_boolean:
  my_fancy_switch:
    name: Fancy Switch
    initial: off

automation:
  - alias: turn on when fancy switch on
    trigger: 
      - platform: state
        entity_id: input_boolean.my_fancy_switch
        to: 'on'
    action:
      - service: ifttt.trigger
        data: {"event":"lounge_dimmed_50", "value1":"on"}
  - alias: turn off when fancy switch off
    trigger: 
      - platform: state
        entity_id: input_boolean.my_fancy_switch
        to: 'off'
    action:
      - service: ifttt.trigger
        data: {"event":"lounge_dimmed_50", "value1":"off"}
2 Likes

That works great, thanks a lot of the help!

No problem! Glad I can help.

…so now I’m trying to combine them and turn on/off 2 IFTTT triggers at once. I’ve tried lots of variations based on the existing code. Here’s an example of what I’ve tried, I’m hoping I’m along the right lines (but doesn’t work):

# Living Room Lights
- alias: Turn Living Room Lights on
  trigger:
    - platform: state
      entity_id: input_boolean.ifttt_living_room_lights
      to: 'on'
  action:
    - service: ifttt.trigger
      data:
        event: {"lounge_100", "living_room_100"}
        value1: on

- alias: Turn Living Room Lights off
  trigger:
    - platform: state
      entity_id: input_boolean.ifttt_living_room_lights
      to: 'off'
  action:
    - service: ifttt.trigger
      data:
        event: {"lounge_off", "dining_room_off"}
        value1: off

Any ideas on how to get this to work, turning on/off more than one IFTTT trigger?

I have no idea how your IFTTT is set up. My ifttt sends me a text message with the contents of value1 being sent as the message. The IFTTT Applet Name is “HomeAssistantValue1”, and my message is “Main Door Open”. This is my example:

- alias: Message trigger on main door
  trigger:
    - platform: state
      entity_id: sensor.main_door_hindge
      to: 'open'
  action:
    - service: ifttt.trigger
      data: {"event":"HomeAssistantValue1","value1":"Main Door Open"}

Written out like your example, it would look like this:

- alias: Message trigger on main door
  trigger:
    - platform: state
      entity_id: sensor.main_door_hindge
      to: 'open'
  action:
    - service: ifttt.trigger
      data:
        event: "HomeAssistantValue1"
        value1: "Main Door Open"

You are going to need to make an on & off trigger for each device.

Why are you using IFTTT to turn on and off lights anyways? There are so many better ways. What type of device is this?

Actually, I don’t really need it for this. I’m using a script to control some LightwaveRF lights, and I was using IFTTT while I had a problem with them.

I guess I was more interested in learning to use IFTTT in different ways with Home Assistant than controlling these particular lights :slight_smile:

I get ya. You like to tinker! That’s all I’ve done with my automation since I got it. I wish I could help you further, but I’ve only set up Text messaging… I haven’t really investigated other IFTTT uses aside from notifications.

Here is how I would do it to

- alias: Turn Living Room Lights on/off
  trigger:
    - platform: state
      entity_id: input_boolean.ifttt_living_room_lights
  action:
    - service: ifttt.trigger
      data_template:
        event: "{% if trigger.to_state.state == 'on' %}lounge_100{% else %}lounge_off{% endif %}
        value1: "{{ trigger.to_state.state }}"
    - service: ifttt.trigger
      data_template:
        event: "{% if trigger.to_state.state == 'on' %}dining_room_100{% else %}dining_room_off{% endif %}
        value1: "{{ trigger.to_state.state }}"

This combines the separate on and off automations into one and triggers the IFTTT service for both lounge and dining room.

1 Like

Heh, exactly. I just like to tinker :smile:

Great, thanks a lot for the help!

I have a similar problem… I need to have a virtual switch to turn on and off a Sonoff Switch triggered in IFTTT but do not works… why???

input_boolean:
  notify_home:
    name: sonoff on/off
    initial: off
    icon: mdi:lightbulb

  - alias: sonoff on
    trigger:
      platform: state
      entity_id: input_boolean.notify_home
      to: 'on'
    action:
      service: ifttt.trigger
      data: {"event":"Sonoff_on", "value1":"on"}

  - alias: sonoff off
    trigger:
      platform: state
      entity_id: input_boolean.notify_home
      to: 'off'
    action:
      service: ifttt.trigger
      data: {"event":"Sonoff_off", "value1":"off"}

problem solved… a syntax error… after trigger the platform row must have a -

  • alias: sonoff on
    trigger:
    • platform: state
      entity_id: input_boolean.notify_home
      to: ‘on’
      action:
      service: ifttt.trigger
      data: {“event”:“Sonoff_on”, “value1”:“on”}

I got it working, but when I put more than 2 switchs only one show up on the web page. How can I put more thant one switch ?

Thanks !

here is my config

input_boolean:
my_fancy_switch:
name: MerossSW1
initial: off

automation:

  • alias: turn on when fancy switch on
    trigger:
    • platform: state
      entity_id: input_boolean.my_fancy_switch
      to: ‘on’
      action:
    • service: ifttt.trigger
      data: {“event”:“MerossO1_on”, “value1”:“on”}
  • alias: turn off when fancy switch off
    trigger:
    • platform: state
      entity_id: input_boolean.my_fancy_switch
      to: ‘off’
      action:
    • service: ifttt.trigger
      data: {“event”:“MerossO1_off”, “value1”:“off”}

This work, but when I try to add another one it’s not working.

you need to post your full config with both. I have an idea of what could be causing your problem…

place input_boolean: only once in configuration.yaml

input_boolean:
  tvlampe:
    name: TV Lampe
    initial: off
    icon: mdi:lamp
  fernseher:
    name: Fernseher
    initial: off
    icon: mdi:television

I have managed to set up a trigger on/off that is integrated HA => IFTTT, but how to make integration working two ways? That if somebody pushes the button on the physical switch the state in HA will be updated?

Probably something like this:
trigger: ifttt
action: state
But I have no idea how to set it up properly

my setup in automations.yaml

  - alias: turn on when sonoff_light_bedroom_b switch on
    trigger: 
      - platform: state
        entity_id: input_boolean.sonoff_light_bedroom_b
        to: 'on'
    action:
      - service: ifttt.trigger
        data: {"event":"sonoff_light_bedroom_b_on"}
  - alias: turn off when sonoff_light_bedroom_b switch off
    trigger: 
      - platform: state
        entity_id: input_boolean.sonoff_light_bedroom_b
        to: 'off'
    action:
      - service: ifttt.trigger
        data: {"event":"sonoff_light_bedroom_b_off"}