Input Boolean with IFTTT

Hi, I’m a newbie, I’m creating a smoking room with light and smoke-fan and this is what I want to make:

I’d like to have a control panel with on/off switches that send IFTTT command. I need a switch that when is on can send “turn it on” to my IFTTT devices and send “shut down” when is turned off.

I’ve created my IFTTT applet and are working from my phone with Google Assistant, so I’m sure that the command reaches my devices.

I started to write down yaml configuration, but I got a lot of trouble.

Please can anyone check my code and help me?

Thanks

configuration.yaml

# Zona Fumatori
ifttt:
 key: secret_code

luci_fumatori_accese:
 sequence:
  - service: ifttt.trigger
    data_template: {"event": "luci_fumatori_on"}

luci_fumatori_spente:
 sequence:
  - service: ifttt.trigger
    data_template: {"event": "luci_fumatori_off"}

aspiratore_fumatori_acceso:
 sequence:
  - service: ifttt.trigger
    data_template: {"event": "aspiratore_fumatori_on"}

aspiratore_fumatori_spento:
 sequence:
  - service: ifttt.trigger
    data_template: {"event": "aspiratore_fumatori_off"}

# luci Fumatori
input_boolean:
 luci_fumatori:
    name: Luci Fumatori
    initial: off
    icon: mdi:lightbulb-outline
    
 aspiratore_fumatori:
    name: Aspiratore Fumatori
    initial: off
    icon: mdi:fan

# Cloud
cloud:

group: !include groups.yaml
automation: !include automations.yaml

groups.yaml

group:
  view: yes
  entities:
   - group.ZonaFumatori
ZonaFumatori:
 name: Zona Fumatori
 entities:
  - switch.luci_fumatori_accese
  - switch.luci_fumatori_spente
  - switch.aspiratore_fumatori_acceso
  - switch.aspiratore_fumatori_spento

automation.yaml

automation:
 - alias: 'Luci Zona Fumatori'
   trigger:
    platform: homeassistant
    event: start
   condition:
     entity_id: input_boolean.luci_fumatori
     state: true
   action:
     service: ifttt.trigger
     data: {"event": "luci_fumatori_on"}

 - alias: 'Aspiratore Zona Fumatori'
   trigger:
    platform: homeassistant
    event: start
   condition:
     entity_id: input_boolean.aspiratore_fumatori
     state: true
   action:
     service: ifttt.trigger
     data: {"event": "aspiratore_fumatori_on"}

IMO you are going about this the wrong way. If you want a toggle that sends on/off to 2 different sequences, use a switch template. No automations required. You’ll need to figure out something for the status of the switch but you can at least program the on/off explicitly.

ok, thank you, I’ll try and make you know!!!

I used this page like this:

 
switch:
  - platform: template
    switches:
      luci_fumatori:
        friendly_name: "Luci Fumatori"
        icon_template: mdi:lightbulb-outline
        value_template: "{{ is_state('input_boolean.luci_aspiratore', 'on') }}"
        turn_on:
          service: ifttt.trigger
          data_template: {"event": "luci_fumatori_on"}
            entity_id: switch.luci_fumatori_acceso
        turn_off:
          service: ifttt.trigger
          data_template: {"event": "luci_fumatori_off"}
            entity_id: switch.luci_fumatori_spento

but:

General Errors:
- Error loading /Users/dan/.homeassistant/configuration.yaml: while parsing a block mapping
in “/Users/dan/.homeassistant/configuration.yaml”, line 78, column 11
expected , but found ‘’
in “/Users/dan/.homeassistant/configuration.yaml”, line 80, column 13

You don’t need your scripts, if you are using the input boolean as your on/off indicator, then you need to turn that on/off as well.

  turn_off:
    - service: home_assistant.turn_off
      entity_id: input_boolean.luci_aspiratore
    - service: ifttt.trigger
      data: 
        event: "luci_fumatori_off"

I suggest you brush up on the yaml, converting json dictionaries to yaml, and the home assistant database. You should look into what domains are.

Thanks so much!

I did like this:
configuration.yaml

switch:
  - platform: template
    switches:
      zona_fumatori:
        friendly_name: "Zona Fumatori (luci+aspiratore)"
        icon_template: mdi:smoking
        value_template: "{{ is_state('switch.zona_fumatori', 'on') }}"
        turn_on:
         - service: ifttt.trigger
           data_template: {"event": "aspiratore_fumatori_on"}
         - service: ifttt.trigger
           data_template: {"event": "luci_fumatori_on"}
        turn_off:
         - service: home_assistant.turn_off
           entity_id: switch.zona_fumatori
         - service: ifttt.trigger
           data: 
            event: "luci_fumatori_off"
         - service: ifttt.trigger
           data: 
            event: "aspiratore_fumatori_off"
      luci_fumatori:
        friendly_name: "Luci Fumatori"
        icon_template: mdi:lightbulb-outline
        value_template: "{{ is_state('switch.luci_fumatori', 'on') }}"
        turn_on:
          - service: home_assistant.turn_on
            entity_id: switch.luci_fumatori
          - service: ifttt.trigger
            data: 
             event: "luci_fumatori_on"
        turn_off:
          - service: home_assistant.turn_off
            entity_id: switch.luci_fumatori
          - service: ifttt.trigger
            data: 
             event: "luci_fumatori_off"
      aspiratore_fumatori:
        friendly_name: "Aspiratore Fumatori"
        icon_template: mdi:fan
        value_template: "{{ is_state('switch.aspiratore_fumatori', 'on') }}"
        turn_on:
          service: ifttt.trigger
          data_template: {"event": "aspiratore_fumatori_on"}
        turn_off:
          - service: home_assistant.turn_off
            entity_id: switch.aspiratore_fumatori
          - service: ifttt.trigger
            data: 
             event: "aspiratore_fumatori_off"

customize.yaml

switch.luci_fumatori:
  assumed_state: true
switch.aspiratore_fumatori:
  assumed_state: true
switch.zona_fumatori:
  assumed_state: true
1 Like

I don’t think that will work, you are referencing itself inside itself.

You’ll need those input_booleans instead.

ok, I changed…but was working also with autoreference (???)!!!

If it works, then use it. but you may run into errors when the object is referencing itself. I could see it become a memory leak because calling turn_on will call tun_on which will call turn_on which will call turn_on… forever.

I changed back to input_boolean
like this:

switches:
      zona_fumatori:
        friendly_name: "Zona Fumatori (luci+aspiratore)"
        value_template: "{{ is_state('input_boolean.zona_fumatori', 'on') }}"
        icon_template:
          "{% if is_state('input_boolean.zona_fumatori', 'on') %}
            mdi:smoking
          {% else %}
            mdi:smoking-off
          {% endif %}"
        turn_on:
         - service: ifttt.trigger
           data_template: {"event": "aspiratore_fumatori_on"}
         - service: ifttt.trigger
           data_template: {"event": "luci_fumatori_on"}
        turn_off:
         - service: home_assistant.turn_off
           entity_id: input_boolean.zona_fumatori
         - service: ifttt.trigger
           data: 
            event: "luci_fumatori_off"
         - service: ifttt.trigger
           data: 
            event: "aspiratore_fumatori_off"
      luci_fumatori:
        friendly_name: "Luci Fumatori"
        value_template: "{{ is_state('input_boolean.luci_fumatori', 'on') }}"
        icon_template:
          "{% if is_state('input_boolean.luci_fumatori', 'on') %}
            mdi:lightbulb-on-outline
          {% else %}
            mdi:lightbulb-outline
          {% endif %}"
        turn_on:
          - service: home_assistant.turn_on
            entity_id: input_boolean.luci_fumatori
          - service: ifttt.trigger
            data: 
             event: "luci_fumatori_on"
        turn_off:
          - service: home_assistant.turn_off
            entity_id: input_boolean.luci_fumatori
          - service: ifttt.trigger
            data: 
             event: "luci_fumatori_off"
      aspiratore_fumatori:
        friendly_name: "Aspiratore Fumatori"
        value_template: "{{ is_state('input_boolean.aspiratore_fumatori', 'on') }}"
        icon_template:
          "{% if is_state('input_boolean.aspiratore_fumatori', 'on') %}
            mdi:fan
          {% else %}
            mdi:fan-off
          {% endif %}"
        turn_on:
          - service: home_assistant.turn_on
            entity_id: input_boolean.luci_fumatori
          - service: ifttt.trigger
            data: 
             event: "aspiratore_fumatori_on"
        turn_off:
          - service: home_assistant.turn_off
            entity_id: input_boolean.aspiratore_fumatori
          - service: ifttt.trigger
            data: 
             event: "aspiratore_fumatori_off"

and it works fine!!! (a little bit of lag, but ok!)

but can’t change icon according to status…or have a sort of light on/off

There will be lag on the interface, you’ll train yourself to ignore that. If you are getting lag to your devices, reorder the services in turn_on/turn_off. Place your highest priority items first, and placing input_boolean last because that’s just visual.

1 Like

I changed putting the “icon code” at the and to be solved after the switch selection…but doesn’t work…

[...]
aspiratore_fumatori:
        friendly_name: "Aspiratore Fumatori"
        value_template: "{{ is_state('input_boolean.aspiratore_fumatori', 'on') }}"
        turn_on:
          - service: home_assistant.turn_on
            entity_id: input_boolean.luci_fumatori
          - service: ifttt.trigger
            data: 
             event: "aspiratore_fumatori_on"
        turn_off:
          - service: home_assistant.turn_off
            entity_id: input_boolean.aspiratore_fumatori
          - service: ifttt.trigger
            data: 
             event: "aspiratore_fumatori_off"
        icon_template:
          "{% if is_state('input_boolean.aspiratore_fumatori', 'on') %}
            mdi:fan
          {% else %}
            mdi:fan-off
          {% endif %}"
[...]

No no no, When i was saying reorganize the services, i mean just the services. Not the other attributes.

These are the services under turn_on:
- service: home_assistant.turn_on
entity_id: input_boolean.luci_fumatori
- service: ifttt.trigger
data:
event: “aspiratore_fumatori_on”

These are the servcies under turn_off:

      - service: home_assistant.turn_off
        entity_id: input_boolean.aspiratore_fumatori
      - service: ifttt.trigger
        data: 
         event: "aspiratore_fumatori_off"

Re order those, example:

      - service: ifttt.trigger
        data: 
          event: "aspiratore_fumatori_off"
      - service: home_assistant.turn_off
        entity_id: input_boolean.aspiratore_fumatori

Also, you need another space before the word event in all your ifttt.trigger services.

Hello DanPal
I’m also a newbie
I’m trying to realise a similar Solution like you. Can you provide me your code, please?

Greetings from switzerland
Tom

His code is posted multiple times in this thread. Just take a look at his last few comments. Both have working versions of his code

Hello Petro
I have no idea which parts of the code I need. Isn’t it possible that you can send me a copy of the code I need?

Greetings
Tom

Every automation is unique, copying and pasting code won’t work. You’ll have to doctor it, this link has the info you want:

Petro

Many thanks to you. I’ll try it.

Greetins
Tom