Toggle on a switch using esphome automation based on ir recviver codecs

I am trying to automate switches based upon specific IR code received by the receiver, my esphome contains 4 switches and few sensors and IR reciver the code i got from a remote is based on nec format

esphome confg

switch:
  - platform: gpio
    pin: D0
    name: "Tubelight"
    inverted: yes
  - platform: gpio
    pin: D1
    name: "Bulb"
    inverted: yes
  - platform: gpio
    pin: D4
    name: "Fan"
    inverted: yes
  - platform: gpio
    pin: D5
    name: "HallwayBulb"
    inverted: yes
 remote_receiver:
  pin:
    number: D7
    inverted: True
    mode: INPUT_PULLUP
  dump: all
    
    

and the ir code of the remote is as follows

power:
 Received NEC: address=0x01FE, command=0x48B7
1:
 Received NEC: address=0x01FE, command=0x50AF
 2:
 Received NEC: address=0x01FE, command=0xD827
 3:
 Received NEC: address=0x01FE, command=0xF807
 4:
 Received NEC: address=0x01FE, command=0x30CF

when I press the power button on the remote the esp should toggle off all four relays & if press the 1 button then the first device should get switched on , like that every device should get powered on and off

i know i need to use

on_nec (Optional, Automation): An automation to perform when a NEC remote code has been decoded. A variable x of type remote_base::NECData is passed to the automation for use in lambdas.

but I can’t find any documents on how to practically implement on esphome

esphome receiver

please help.

Hi there…For automations to work with the switches you made, first you need give unique ids to the switches like below. Only then we can call then in automations.

switch:
  - platform: gpio
    id: relay_1
    pin: D0
    name: "Tubelight"
    inverted: yes
  - platform: gpio
    id: relay_2
    pin: D1
    name: "Bulb"
    inverted: yes
  - platform: gpio
    id: relay_3
    pin: D4
    name: "Fan"
    inverted: yes
  - platform: gpio
    id: relay_4
    pin: D5
    name: "HallwayBulb"
    inverted: yes

Now to make then work with remote codes, you need to create binary sensor like the following in esphome conifg.

binary_sensor:
  - platform: remote_receiver
    id: all_on
    nec:
      address: 0x01FE
      command: 0x48B7
    on_press:
      then:
        - switch.turn_on: relay_1
        - switch.turn_on: relay_2
        - switch.turn_on: relay_3
        - switch.turn_on: relay_4
  - platform: remote_receiver
    id: all_off
    nec:
      address: 0x01FE
      command: 0x50AF
    on_press:
      then:
        - switch.turn_off: relay_1
        - switch.turn_off: relay_2
        - switch.turn_off: relay_3
        - switch.turn_off: relay_4

This should work for you but If you are having any issues do ask.

Thanks, it works perfectly!

May be helpful for someone who reached from search

github-code

hai sheminasalam , i got ir code like this 9089, -4584, 503, -635, 533, -632, 530, -636, 530, -635, 531, -635, 531, -635, 504, -661, 528, -638, 531, -1713, 529, -1717, 528, -1713, 506, -1738, 530, -1714, 532, -1713, 532, -1713, 530, -1715, 529, -1714, 531, -633, 533, -1712, 558,
-608, 531, -632, 533, -634, 556, -1689, 531, -634, 530, -638, 530, -1712, 530, -636, 530, -1714, 529, -1719, 553, -1684, 534, -635, 529, -1714, 530 , its raw . how i use this

Please see the following link and chose the correct remote type

thank you , still i have doubt
this is the exact code i received from remote
[remote.raw:028]: Received Raw: 9154, -4531, 534, -634, 533, -635, 533, -635, 533, -634, 534, -612, 556, -634, 533, -634, 535, -634, 533, -1692, 554, -1650, 624, -1689, 534, -1712, 534, -1714, 533, -1713, 534, -1690, 556, -1691, 556, -612, 555, -1714, 534, -1712, 534,
[22:29:20][D][remote.raw:041]: -635, 534, -632, 534, -634, 532, -1715, 532, -636, 533, -1715, 532, -635, 532, -634, 532, -1715, 533, -1713, 534, -1713, 535, -634, 531, -1715, 532

can you help

binary_sensor:

  • platform: remote_receiver

    name: “Yamaha power”

    raw:

    code: [9089, -4584, 503, -635, 533, -632, 530, -636, 530, -635, 531, -635, 531, -635, 504, -661, 528, -638, 531, -1713, 529, -1717, 528, -1713, 506, -1738, 530, -1714, 532, -1713, 532, -1713, 530, -1715, 529, -1714, 531, -633, 533, -1712, 558,

-608, 531, -632, 533, -634, 556, -1689, 531, -634, 530, -638, 530, -1712, 530, -636, 530, -1714, 529, -1719, 553, -1684, 534, -635, 529, -1714, 530]

on_press:

  then:

    - switch.turn_on: relay1

    - switch.turn_on: relay2

    - switch.turn_on: relay3

    - switch.turn_on: relay4
  • platform: remote_receiver

    name: “Yamaha power”

    raw:

    code: [3016, -3097, 2988, -4529, 518, -1722, 519, -600, 519, -1723, 544, -573, 520, -597, 550, -1690, 549, -1695, 518, -598, 521, -1719, 521, -602, 518, -626, 493, -599, 549, -571, 521, -1718, 522, -1717, 521, -600, 521, -599, 519, -1720, 522,

-1694, 546, -595, 523, -626, 490, -602, 521, -602, 519, -600, 547, -573, 547, -572, 521, -598, 523, -599, 493, -626, 495, -625, 608, -511, 519, -626, 495, -600, 524, -1715, 522, -622, 497, -599, 572, -548, 540, -604, 496, -600, 520, -604, 516, -599,

549, -570, 523, -1694, 544, -625, 497, -595, 526, -597, 547, -573, 519, -600, 520, -1719, 521, -625, 497, -596, 522, -625, 524, -571, 520, -655, 466, -598, 496, -627, 519, -600, 519, -598, 523, -1718, 520, -652, 468, -626, 494, -600, 496, -621, 548,

-601, 495, -625, 500, -595, 520, -624, 497, -598, 521, -599, 522, -600, 518, -600, 523, -599, 518, -626, 495, -600, 520, -599, 520, -601, 522, -596, 524, -623, 493, -605, 518, -625, 496, -602, 520, -598, 521, -598, 523, -597, 521, -602, 517, -627, 495,

-624, 497, -600, 519, -600, 521, -626, 470, -626, 517, -606, 517, -598, 522, -623, 497, -624, 495, -599, 521, -629, 492, -626, 468, -626, 522, -624, 494, -1719, 521, -599, 547, -577, 517, -600, 523, -1719, 518, -602, 518, -601, 521, -1744, 496, -600,

518, -1722, 517, -602, 520, -601, 518]

on_press:

  then:

    - switch.turn_off: relay1

    - switch.turn_off: relay2

    - switch.turn_off: relay3

    - switch.turn_off: relay4

while using this code ,in log i am getting this message but not switch on the relay also getting ][binary_sensor:036]: ‘Yamaha power’: Sending state OFF immediately after switch on without pressing switch off ir remote

[C][api:139]: Address: esp44.local:6053
[22:36:48][C][api:141]: Using noise encryption: YES
[22:36:51][D][binary_sensor:036]: ‘Yamaha power’: Sending state ON
[22:36:51][D][switch:013]: ‘1’ Turning ON.
[22:36:51][D][switch:013]: ‘2’ Turning ON.
[22:36:51][D][switch:013]: ‘3’ Turning ON.
[22:36:51][D][switch:013]: ‘4’ Turning ON.
[22:36:51][D][binary_sensor:036]: ‘Yamaha power’: Sending state OFF
[22:36:58][W][api.connection:083]: ESPH

So you are saying the automation to switch the relays on is not working. Can you share the entire code . Please make sure you change passwords and all before sharing.

esphome:
name: esp44

esp32:
board: esp32dev
framework:
type: arduino

Enable logging

logger:

Enable Home Assistant API

api:
encryption:
key: “”

ota:
password: “”

wifi:
ssid: “bsnlkerala”
password: “b2378”

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Esp44 Fallback Hotspot”
password: “343737”

binary_sensor:

  • platform: remote_receiver
    name: “Yamaha power”
    raw:
    code: [9089, -4584, 503, -635, 533, -632, 530, -636, 530, -635, 531, -635, 531, -635, 504, -661, 528, -638, 531, -1713, 529, -1717, 528, -1713, 506, -1738, 530, -1714, 532, -1713, 532, -1713, 530, -1715, 529, -1714, 531, -633, 533, -1712, 558,
    -608, 531, -632, 533, -634, 556, -1689, 531, -634, 530, -638, 530, -1712, 530, -636, 530, -1714, 529, -1719, 553, -1684, 534, -635, 529, -1714, 530]

    on_press:
    then:
    - switch.turn_on: relay1
    - switch.turn_on: relay2
    - switch.turn_on: relay3
    - switch.turn_on: relay4

  • platform: remote_receiver
    name: “Yamaha power”
    raw:
    code: [3016, -3097, 2988, -4529, 518, -1722, 519, -600, 519, -1723, 544, -573, 520, -597, 550, -1690, 549, -1695, 518, -598, 521, -1719, 521, -602, 518, -626, 493, -599, 549, -571, 521, -1718, 522, -1717, 521, -600, 521, -599, 519, -1720, 522,
    -1694, 546, -595, 523, -626, 490, -602, 521, -602, 519, -600, 547, -573, 547, -572, 521, -598, 523, -599, 493, -626, 495, -625, 608, -511, 519, -626, 495, -600, 524, -1715, 522, -622, 497, -599, 572, -548, 540, -604, 496, -600, 520, -604, 516, -599,
    549, -570, 523, -1694, 544, -625, 497, -595, 526, -597, 547, -573, 519, -600, 520, -1719, 521, -625, 497, -596, 522, -625, 524, -571, 520, -655, 466, -598, 496, -627, 519, -600, 519, -598, 523, -1718, 520, -652, 468, -626, 494, -600, 496, -621, 548,
    -601, 495, -625, 500, -595, 520, -624, 497, -598, 521, -599, 522, -600, 518, -600, 523, -599, 518, -626, 495, -600, 520, -599, 520, -601, 522, -596, 524, -623, 493, -605, 518, -625, 496, -602, 520, -598, 521, -598, 523, -597, 521, -602, 517, -627, 495,
    -624, 497, -600, 519, -600, 521, -626, 470, -626, 517, -606, 517, -598, 522, -623, 497, -624, 495, -599, 521, -629, 492, -626, 468, -626, 522, -624, 494, -1719, 521, -599, 547, -577, 517, -600, 523, -1719, 518, -602, 518, -601, 521, -1744, 496, -600,
    518, -1722, 517, -602, 520, -601, 518]

    on_press:
    then:
    - switch.turn_off: relay1
    - switch.turn_off: relay2
    - switch.turn_off: relay3
    - switch.turn_off: relay4

captive_portal:

remote_receiver:
pin:
number: 33
inverted: true
mode:
input: true
pullup: true
dump: raw
remote_transmitter:
pin: GPIO13

Infrared remotes use a 50% carrier signal

carrier_duty_percent: 50%

switch:

  • platform: template
    name: “AC ON”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3115, -2995, 3114, -4405, 620, -1619, 619, -499, 621, -1620, 619, -498, 621, -499, 621, -1619, 620, -1620, 619, -499, 620, -1619, 620, -501, 619, -498, 622, -500, 619, -499, 621, -1620, 616, -1621, 621, -500, 619, -499, 619, -1620, 619,
    -1621, 618, -502, 619, -499, 617, -504, 618, -501, 618, -501, 619, -501, 618, -503, 617, -501, 617, -503, 616, -504, 617, -502, 618, -502, 616, -503, 616, -504, 616, -1624, 615, -503, 616, -505, 614, -505, 615, -505, 614, -506, 610, -509, 615, -505,
    614, -506, 613, -1627, 611, -509, 613, -505, 611, -510, 612, -507, 609, -510, 611, -510, 609, -511, 609, -510, 609, -512, 608, -512, 607, -512, 609, -511, 606, -513, 607, -514, 606, -513, 607, -1633, 603, -517, 603, -516, 603, -517, 604, -515, 604,
    -516, 603, -517, 577, -543, 576, -544, 598, -521, 602, -518, 603, -516, 602, -519, 600, -520, 599, -520, 575, -546, 574, -546, 573, -565, 554, -566, 554, -567, 553, -567, 552, -567, 553, -568, 552, -568, 551, -569, 551, -569, 550, -570, 550, -571, 548,
    -571, 549, -572, 546, -574, 546, -575, 544, -577, 542, -578, 542, -579, 540, -602, 518, -602, 518, -579, 541, -601, 519, -602, 517, -603, 518, -601, 519, -601, 519, -1721, 518, -602, 518, -1722, 518, -602, 518, -602, 518, -602, 519, -1721, 519, -601,
    518, -602, 518, -602, 518, -1722, 517]

  • platform: template
    name: “AC OFF”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3118, -2995, 3113, -4404, 623, -1612, 625, -497, 625, -1613, 625, -494, 623, -498, 621, -1618, 620, -1642, 598, -497, 624, -1615, 622, -498, 621, -497, 623, -496, 625, -495, 622, -498, 623, -496, 623, -497, 621, -499, 618, -1621, 620,
    -1620, 621, -496, 623, -498, 621, -500, 618, -501, 619, -500, 620, -500, 595, -525, 620, -499, 620, -499, 622, -499, 619, -502, 594, -524, 595, -525, 621, -498, 620, -500, 596, -524, 620, -501, 619, -499, 594, -527, 617, -502, 591, -529, 592, -527,
    593, -527, 593, -1647, 590, -528, 619, -503, 589, -530, 590, -529, 610, -510, 616, -504, 590, -530, 615, -505, 588, -531, 589, -532, 611, -509, 611, -508, 612, -508, 610, -510, 586, -534, 585, -1656, 584, -534, 585, -535, 583, -537, 584, -536, 584,
    -535, 584, -536, 583, -538, 583, -537, 583, -536, 584, -537, 583, -536, 583, -538, 583, -537, 584, -536, 583, -538, 583, -537, 607, -514, 606, -514, 585, -534, 582, -539, 604, -516, 605, -515, 603, -517, 579, -542, 578, -541, 579, -542, 578, -541, 579,
    -542, 577, -543, 576, -544, 576, -544, 577, -543, 577, -542, 602, -519, 576, -544, 576, -544, 576, -544, 575, -546, 575, -545, 574, -546, 575, -546, 574, -547, 572, -1686, 555, -565, 554, -1686, 553, -1687, 552, -1688, 552, -568, 552, -569, 551, -1689,
    551, -569, 550, -1691, 548, -1692, 548]

  • platform: template
    name: “AC QUIET”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3016, -3097, 2988, -4529, 518, -1722, 519, -600, 519, -1723, 544, -573, 520, -597, 550, -1690, 549, -1695, 518, -598, 521, -1719, 521, -602, 518, -626, 493, -599, 549, -571, 521, -1718, 522, -1717, 521, -600, 521, -599, 519, -1720, 522,
    -1694, 546, -595, 523, -626, 490, -602, 521, -602, 519, -600, 547, -573, 547, -572, 521, -598, 523, -599, 493, -626, 495, -625, 608, -511, 519, -626, 495, -600, 524, -1715, 522, -622, 497, -599, 572, -548, 540, -604, 496, -600, 520, -604, 516, -599,
    549, -570, 523, -1694, 544, -625, 497, -595, 526, -597, 547, -573, 519, -600, 520, -1719, 521, -625, 497, -596, 522, -625, 524, -571, 520, -655, 466, -598, 496, -627, 519, -600, 519, -598, 523, -1718, 520, -652, 468, -626, 494, -600, 496, -621, 548,
    -601, 495, -625, 500, -595, 520, -624, 497, -598, 521, -599, 522, -600, 518, -600, 523, -599, 518, -626, 495, -600, 520, -599, 520, -601, 522, -596, 524, -623, 493, -605, 518, -625, 496, -602, 520, -598, 521, -598, 523, -597, 521, -602, 517, -627, 495,
    -624, 497, -600, 519, -600, 521, -626, 470, -626, 517, -606, 517, -598, 522, -623, 497, -624, 495, -599, 521, -629, 492, -626, 468, -626, 522, -624, 494, -1719, 521, -599, 547, -577, 517, -600, 523, -1719, 518, -602, 518, -601, 521, -1744, 496, -600,
    518, -1722, 517, -602, 520, -601, 518]

  • platform: template
    name: “AC TURBO ON”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3043, -3068, 3015, -4504, 520, -1717, 522, -599, 520, -1718, 545, -574, 520, -577, 543, -1719, 520, -1720, 518, -600, 520, -1716, 523, -598, 522, -596, 524, -598, 546, -574, 520, -1717, 522, -1717, 523, -596, 523, -597, 527, -1689, 544,
    -1720, 518, -598, 549, -572, 519, -626, 497, -598, 519, -602, 519, -601, 544, -598, 494, -601, 520, -601, 519, -601, 545, -572, 520, -599, 521, -599, 520, -598, 547, -1692, 522, -602, 516, -600, 520, -601, 520, -596, 523, -598, 520, -599, 521, -601,
    519, -603, 516, -1719, 520, -626, 520, -576, 518, -600, 543, -580, 516, -602, 519, -599, 519, -603, 544, -573, 522, -600, 519, -600, 519, -601, 521, -624, 494, -601, 518, -601, 546, -574, 520, -1721, 518, -600, 521, -597, 520, -601, 521, -600, 519,
    -599, 521, -598, 522, -600, 519, -626, 521, -574, 520, -599, 520, -603, 544, -573, 521, -625, 522, -572, 545, -576, 544, -600, 494, -624, 496, -625, 494, -601, 521, -623, 496, -625, 495, -597, 524, -624, 495, -598, 522, -623, 495, -600, 521, -599, 545,
    -575, 545, -603, 492, -626, 494, -625, 495, -601, 518, -599, 522, -598, 522, -601, 518, -601, 520, -624, 521, -600, 494, -626, 520, -575, 519, -624, 496, -1747, 492, -625, 494, -602, 518, -603, 517, -626, 496, -598, 521, -625, 493, -1746, 494, -601,
    518, -1720, 520, -601, 519, -601, 517]

  • platform: template
    name: “AC temperature 16”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3014, -3097, 2987, -4552, 495, -1719, 550, -571, 519, -1720, 520, -601, 520, -624, 494, -1718, 523, -1717, 494, -627, 520, -598, 545, -574, 522, -599, 521, -596, 523, -599, 519, -1720, 520, -1719, 521, -603, 516, -598, 521, -1718, 521,
    -1719, 522, -598, 518, -602, 521, -601, 516, -601, 520, -600, 519, -602, 518, -625, 495, -597, 549, -571, 522, -599, 496, -626, 521, -599, 520, -597, 550, -573, 519, -1744, 494, -602, 518, -601, 517, -576, 544, -627, 496, -597, 522, -598, 523, -599,
    493, -1743, 520, -600, 521, -602, 517, -599, 522, -597, 524, -622, 495, -626, 495, -598, 524, -597, 520, -607, 513, -599, 520, -600, 521, -599, 520, -625, 495, -625, 495, -600, 517, -625, 495, -1744, 495, -599, 521, -599, 524, -596, 521, -626, 522,
    -598, 495, -624, 498, -622, 493, -600, 550, -571, 519, -626, 494, -600, 521, -599, 519, -598, 549, -575, 520, -623, 496, -625, 493, -626, 495, -623, 497, -601, 520, -598, 519, -626, 495, -601, 492, -653, 496, -597, 522, -598, 519, -626, 496, -623, 496,
    -624, 494, -602, 518, -628, 493, -626, 468, -627, 546, -573, 517, -600, 524, -601, 515, -603, 552, -591, 495, -626, 495, -625, 467, -627, 494, -652, 518, -601, 467, -630, 517, -600, 548, -1692, 520, -1720, 521, -597, 520, -1720, 519, -602, 516, -1749,
    490, -1721, 494, -625, 520, -1719, 518]

  • platform: template
    name: “AC temperature 17”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3044, -3069, 3017, -4502, 521, -1718, 522, -599, 522, -1718, 522, -597, 522, -599, 520, -1719, 546, -1692, 524, -599, 520, -599, 521, -577, 544, -598, 523, -1718, 519, -600, 521, -1720, 520, -1718, 548, -571, 523, -600, 520, -1695, 545,
    -1717, 522, -597, 523, -625, 496, -599, 521, -598, 523, -598, 521, -600, 520, -602, 521, -597, 521, -600, 522, -599, 521, -598, 522, -598, 522, -625, 496, -599, 522, -1718, 520, -600, 520, -600, 521, -602, 518, -628, 493, -600, 521, -599, 521, -601,
    518, -1721, 520, -598, 523, -602, 517, -600, 520, -602, 520, -598, 522, -600, 519, -602, 544, -577, 518, -625, 497, -599, 519, -603, 518, -626, 522, -572, 521, -600, 545, -575, 521, -602, 518, -1745, 496, -600, 519, -600, 521, -600, 520, -600, 519,
    -599, 521, -626, 496, -575, 544, -600, 522, -597, 533, -590, 518, -600, 522, -599, 519, -601, 520, -625, 519, -574, 521, -604, 516, -599, 522, -601, 520, -598, 522, -625, 495, -624, 495, -600, 521, -599, 522, -597, 521, -625, 494, -626, 496, -600, 520,
    -601, 519, -626, 493, -628, 494, -599, 520, -600, 520, -601, 519, -602, 518, -626, 496, -624, 495, -625, 496, -600, 520, -600, 518, -606, 515, -601, 520, -626, 495, -599, 546, -575, 543, -577, 519, -1721, 520, -601, 518, -1725, 543, -1694, 519, -1745,
    520, -1693, 521, -602, 518, -625, 495]

  • platform: template
    name: “AC temperature 18”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3039, -3094, 3016, -4503, 522, -1715, 525, -597, 521, -1718, 550, -570, 522, -599, 520, -1720, 521, -1718, 521, -599, 545, -574, 522, -597, 523, -1717, 522, -600, 520, -599, 521, -1718, 521, -1718, 521, -604, 516, -600, 520, -1716, 524,
    -1720, 519, -600, 546, -574, 547, -573, 548, -571, 521, -599, 522, -599, 523, -599, 520, -598, 522, -624, 495, -600, 520, -601, 519, -602, 520, -597, 522, -600, 518, -1720, 521, -600, 521, -598, 523, -598, 521, -599, 520, -603, 518, -599, 520, -601,
    545, -1693, 521, -599, 521, -599, 520, -601, 519, -600, 521, -600, 520, -601, 521, -599, 520, -601, 519, -624, 495, -603, 518, -626, 496, -600, 543, -573, 524, -599, 522, -601, 517, -599, 522, -1720, 518, -600, 520, -601, 520, -600, 521, -624, 496,
    -598, 522, -599, 521, -626, 519, -576, 519, -600, 521, -599, 524, -597, 520, -599, 520, -601, 521, -599, 519, -600, 523, -625, 493, -600, 520, -600, 547, -575, 545, -575, 519, -602, 518, -602, 516, -604, 519, -601, 524, -594, 519, -603, 518, -625, 496,
    -600, 520, -602, 517, -601, 521, -599, 546, -574, 521, -599, 520, -600, 519, -602, 544, -601, 496, -600, 518, -600, 494, -629, 518, -601, 518, -602, 519, -600, 519, -602, 520, -599, 517, -604, 519, -1745, 494, -1722, 520, -624, 495, -625, 497, -1716,
    547, -1694, 521, -598, 520, -603, 519]

  • platform: template
    name: “AC temperature 19”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3044, -3067, 3046, -4472, 551, -1686, 551, -571, 550, -1690, 548, -571, 572, -548, 551, -1689, 549, -1710, 528, -572, 549, -570, 549, -570, 549, -1692, 548, -1689, 549, -571, 576, -1664, 573, -1668, 550, -567, 576, -547, 574, -1663, 549,
    -1689, 551, -571, 573, -545, 548, -573, 574, -545, 574, -546, 573, -547, 572, -546, 572, -547, 550, -571, 549, -570, 549, -572, 573, -548, 545, -574, 570, -549, 572, -1667, 548, -573, 546, -573, 571, -548, 571, -569, 526, -573, 570, -550, 546, -594,
    526, -1693, 546, -1714, 550, -570, 550, -570, 549, -570, 549, -549, 571, -570, 547, -572, 549, -572, 523, -596, 548, -572, 547, -572, 523, -597, 548, -572, 547, -573, 545, -574, 547, -574, 545, -1693, 545, -576, 520, -600, 544, -576, 519, -601, 543,
    -576, 531, -590, 543, -576, 544, -576, 543, -577, 543, -577, 542, -577, 519, -601, 543, -576, 543, -578, 543, -576, 544, -577, 542, -578, 543, -576, 543, -577, 542, -578, 542, -577, 543, -579, 541, -578, 541, -578, 544, -591, 527, -578, 543, -577, 543,
    -577, 542, -578, 543, -577, 542, -577, 543, -577, 543, -577, 543, -576, 543, -577, 543, -578, 542, -602, 519, -577, 542, -577, 543, -583, 536, -578, 542, -577, 543, -578, 541, -578, 544, -577, 542, -1697, 541, -1698, 543, -1696, 542, -1721, 519, -1696,
    543, -1697, 540, -579, 543, -578, 542]

  • platform: template
    name: “AC temperature 20”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3040, -3094, 3041, -4475, 524, -1717, 521, -577, 544, -1718, 519, -599, 523, -597, 522, -1718, 521, -1718, 520, -578, 542, -599, 523, -1717, 522, -598, 550, -570, 523, -598, 520, -1720, 519, -1720, 520, -600, 519, -600, 522, -1716, 524,
    -1717, 521, -597, 524, -600, 520, -601, 493, -624, 521, -598, 523, -599, 519, -600, 522, -598, 522, -599, 521, -598, 522, -599, 522, -599, 548, -572, 495, -624, 521, -1718, 522, -597, 524, -574, 543, -574, 548, -598, 547, -552, 543, -598, 496, -626,
    519, -1720, 519, -599, 522, -598, 521, -600, 546, -571, 604, -516, 524, -597, 497, -625, 520, -624, 495, -601, 548, -570, 522, -600, 521, -597, 523, -599, 544, -574, 522, -599, 519, -600, 521, -1720, 545, -574, 545, -574, 522, -598, 496, -625, 547,
    -572, 522, -597, 520, -600, 522, -600, 520, -599, 521, -600, 520, -597, 523, -600, 574, -547, 519, -599, 523, -623, 496, -601, 493, -625, 549, -574, 519, -598, 520, -600, 521, -600, 521, -597, 522, -599, 521, -598, 523, -624, 494, -599, 522, -598, 522,
    -599, 519, -600, 520, -599, 522, -599, 520, -600, 521, -624, 496, -600, 519, -601, 520, -599, 520, -600, 520, -626, 493, -601, 521, -600, 519, -600, 547, -574, 521, -600, 518, -600, 520, -597, 522, -1718, 522, -1746, 493, -1721, 545, -573, 546, -1692,
    520, -1744, 497, -598, 520, -625, 496]

  • platform: template
    name: “AC temperature 21”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3018, -3093, 3016, -4503, 523, -1718, 521, -600, 521, -1717, 523, -571, 546, -600, 523, -1716, 500, -1740, 522, -574, 544, -601, 520, -1719, 519, -601, 521, -1718, 523, -598, 520, -1719, 522, -1716, 523, -599, 521, -598, 523, -1717, 520,
    -1721, 519, -600, 522, -599, 518, -600, 521, -600, 519, -600, 523, -599, 521, -599, 520, -599, 521, -598, 521, -600, 523, -597, 547, -571, 523, -601, 518, -600, 547, -1692, 520, -601, 521, -573, 546, -599, 521, -598, 521, -578, 542, -601, 547, -571,
    521, -1721, 521, -598, 523, -597, 521, -599, 549, -571, 521, -601, 521, -598, 522, -599, 520, -601, 519, -601, 546, -574, 548, -570, 521, -601, 522, -596, 523, -598, 522, -598, 522, -598, 523, -1718, 523, -598, 520, -600, 548, -572, 521, -599, 520,
    -601, 519, -603, 520, -597, 522, -602, 517, -626, 494, -603, 518, -599, 522, -598, 522, -599, 520, -600, 520, -602, 518, -601, 520, -624, 526, -570, 519, -602, 521, -600, 520, -596, 524, -599, 521, -598, 522, -600, 522, -597, 523, -601, 519, -598, 522,
    -599, 521, -600, 494, -626, 520, -575, 546, -598, 522, -601, 546, -573, 520, -602, 520, -600, 521, -596, 525, -623, 497, -598, 521, -601, 494, -624, 522, -599, 519, -602, 518, -603, 518, -602, 494, -1744, 521, -1718, 521, -1719, 547, -1718, 496, -1721,
    519, -1717, 522, -603, 517, -600, 520]

  • platform: template
    name: “AC temperature 22”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3034, -3095, 3017, -4500, 576, -1665, 519, -601, 522, -1693, 545, -598, 521, -600, 495, -1745, 521, -1716, 522, -598, 548, -573, 520, -1718, 521, -1717, 523, -599, 521, -599, 521, -1717, 547, -1693, 520, -600, 521, -599, 547, -1692, 521,
    -1717, 521, -598, 521, -601, 521, -599, 545, -573, 522, -598, 524, -596, 523, -599, 520, -598, 525, -574, 572, -570, 522, -599, 522, -597, 521, -598, 520, -603, 519, -1720, 522, -598, 521, -597, 522, -577, 544, -577, 542, -599, 523, -597, 522, -598,
    524, -1692, 548, -596, 522, -599, 522, -599, 520, -598, 523, -597, 522, -599, 521, -599, 547, -574, 521, -574, 545, -598, 547, -574, 523, -598, 520, -601, 519, -577, 542, -601, 522, -597, 521, -1720, 520, -598, 550, -571, 519, -601, 521, -576, 542,
    -599, 522, -578, 544, -598, 520, -597, 522, -600, 521, -599, 523, -596, 523, -598, 522, -600, 520, -599, 521, -624, 495, -600, 520, -601, 520, -598, 548, -573, 519, -602, 518, -601, 522, -598, 547, -573, 522, -597, 522, -599, 520, -601, 518, -601, 521,
    -598, 521, -600, 520, -600, 522, -597, 521, -601, 519, -599, 522, -601, 544, -599, 495, -601, 520, -600, 519, -601, 519, -626, 496, -599, 546, -573, 546, -576, 543, -577, 518, -601, 521, -599, 519, -601, 521, -601, 518, -602, 542, -576, 522, -1716,
    522, -1719, 519, -626, 495, -598, 548]

  • platform: template
    name: “AC temperature 23”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3040, -3094, 3015, -4504, 521, -1719, 521, -599, 520, -1718, 520, -579, 544, -577, 542, -1718, 522, -1695, 544, -598, 522, -599, 521, -1718, 522, -1695, 545, -1716, 522, -577, 544, -1694, 545, -1718, 522, -596, 524, -599, 521, -1696, 542,
    -1719, 523, -597, 522, -597, 524, -597, 522, -600, 543, -577, 519, -600, 522, -598, 521, -600, 521, -597, 522, -598, 521, -600, 545, -575, 519, -601, 546, -575, 519, -1720, 520, -599, 547, -574, 546, -572, 520, -601, 521, -599, 523, -596, 521, -600,
    521, -1721, 518, -597, 523, -599, 520, -601, 546, -572, 521, -599, 521, -601, 519, -598, 523, -625, 494, -626, 492, -602, 520, -598, 522, -598, 521, -600, 521, -600, 520, -601, 519, -599, 547, -1695, 520, -599, 519, -600, 549, -571, 520, -600, 522,
    -599, 520, -598, 523, -599, 519, -599, 522, -601, 520, -598, 521, -625, 495, -599, 548, -572, 549, -575, 517, -602, 519, -624, 496, -626, 493, -626, 495, -625, 495, -598, 522, -599, 522, -599, 520, -598, 522, -602, 545, -598, 494, -628, 493, -625, 496,
    -602, 518, -599, 522, -600, 545, -575, 519, -600, 519, -603, 518, -600, 521, -600, 519, -624, 494, -601, 521, -599, 520, -600, 521, -598, 523, -625, 494, -598, 521, -600, 545, -603, 492, -625, 494, -602, 520, -599, 520, -624, 498, -1743, 496, -1744,
    518, -1695, 520, -625, 494, -602, 519]

  • platform: template
    name: “AC temperature 24”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [2987, -3125, 2961, -4554, 520, -1744, 471, -677, 443, -1745, 519, -625, 495, -599, 525, -1741, 495, -1719, 520, -600, 548, -1690, 494, -624, 469, -650, 497, -650, 520, -600, 469, -1744, 519, -1747, 494, -677, 444, -597, 522, -1742, 497,
    -1743, 522, -599, 492, -602, 493, -653, 493, -601, 545, -601, 494, -602, 518, -625, 468, -653, 493, -625, 496, -623, 497, -625, 493, -627, 491, -603, 520, -623, 495, -1719, 549, -573, 494, -629, 509, -634, 491, -609, 126, -155, 231, -601, 508, -710,
    422, -626, 494, -1743, 469, -653, 493, -600, 522, -653, 440, -652, 497, -621, 469, -625, 521, -625, 493, -603, 521, -625, 468, -651, 442, -678, 469, -676, 468, -654, 440, -628, 493, -651, 494, -705, 416, -1743, 470, -625, 496, -623, 496, -653, 467,
    -650, 495, -602, 493, -651, 470, -650, 494, -599, 520, -687, 435, -600, 492, -661, 487, -626, 454, -665, 467, -628, 519, -688, 406, -654, 491, -690, 382, -675, 493, -628, 492, -686, 173, -859, 525, -597, 495, -661, 460, -651, 494, -626, 468, -651, 496,
    -599, 520, -689, 405, -624, 521, -602, 493, -626, 493, -659, 487, -599, 471, -703, 399, -796, 392, -632, 488, -627, 467, -652, 470, -677, 416, -678, 494, -599, 495, -622, 496, -654, 467, -654, 466, -635, 485, -677, 444, -650, 495, -1744, 471, -650,
    467, -1748, 490, -1772, 496, -600, 520, -650, 444]

  • platform: template
    name: “AC temperature 25”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3018, -3094, 3017, -4479, 521, -1740, 522, -598, 522, -1693, 547, -599, 545, -553, 542, -1719, 546, -1692, 522, -598, 522, -1716, 523, -599, 520, -599, 522, -1716, 524, -573, 547, -1717, 520, -1720, 521, -600, 518, -600, 523, -1716, 549,
    -1692, 522, -598, 521, -575, 572, -548, 545, -597, 525, -575, 544, -596, 523, -599, 522, -598, 521, -599, 523, -595, 550, -570, 524, -598, 520, -598, 523, -599, 521, -1717, 523, -597, 522, -599, 520, -600, 522, -598, 523, -597, 521, -600, 521, -599,
    521, -1719, 520, -599, 548, -573, 520, -600, 521, -598, 522, -598, 521, -600, 521, -600, 520, -599, 519, -603, 519, -599, 521, -598, 523, -598, 522, -600, 519, -600, 548, -572, 519, -604, 544, -1695, 519, -599, 521, -599, 520, -600, 521, -598, 547,
    -575, 519, -626, 494, -600, 547, -574, 518, -604, 518, -599, 546, -574, 521, -602, 518, -598, 522, -599, 520, -601, 518, -600, 520, -598, 524, -598, 522, -598, 520, -601, 520, -600, 520, -598, 522, -601, 520, -600, 546, -598, 496, -601, 519, -599, 521,
    -604, 516, -625, 495, -601, 520, -625, 494, -599, 523, -599, 518, -600, 521, -602, 544, -575, 521, -599, 521, -598, 521, -626, 495, -624, 495, -626, 521, -572, 548, -575, 518, -600, 519, -600, 522, -601, 518, -602, 520, -1743, 519, -1693, 548, -1719,
    496, -1719, 519, -598, 522, -625, 495]

  • platform: template
    name: “AC temperature 26”
    turn_on_action:
    remote_transmitter.transmit_raw:
    carrier_frequency: 38khz
    code: [3040, -3069, 3017, -4500, 548, -1692, 520, -599, 521, -1695, 546, -600, 518, -599, 521, -1719, 518, -1719, 522, -600, 520, -1717, 548, -572, 519, -1722, 520, -597, 519, -601, 520, -1719, 520, -1720, 520, -602, 517, -600, 520, -1718, 521,
    -1719, 547, -572, 519, -599, 522, -600, 519, -601, 519, -599, 551, -570, 520, -599, 521, -624, 496, -598, 520, -603, 544, -573, 522, -598, 547, -574, 518, -599, 520, -1721, 543, -577, 519, -599, 520, -602, 547, -597, 521, -573, 520, -601, 518, -601,
    519, -1719, 520, -600, 520, -601, 518, -602, 519, -598, 522, -598, 546, -575, 521, -624, 495, -602, 517, -601, 520, -601, 518, -600, 520, -625, 495, -600, 520, -626, 496, -625, 522, -571, 545, -1697, 518, -600, 519, -601, 544, -576, 518, -601, 493,
    -626, 522, -600, 518, -600, 521, -602, 517, -599, 522, -599, 522, -598, 546, -600, 494, -601, 517, -605, 517, -600, 519, -626, 495, -627, 493, -599, 521, -603, 517, -626, 519, -601, 496, -599, 519, -600, 519, -599, 522, -624, 495, -601, 546, -599, 494,
    -625, 495, -626, 493, -603, 519, -599, 520, -601, 521, -600, 518, -600, 521, -625, 494, -601, 519, -602, 542, -600, 522, -601, 494, -601, 518, -626, 494, -625, 495, -600, 521, -626, 520, -576, 517, -601, 546, -1694, 520, -597, 520, -601, 520, -1743,
    496, -1717, 522, -624, 494, -601, 520]

  • platform: gpio
    name: “1”
    pin: GPIO16
    id: relay1
    restore_mode: ALWAYS_OFF
    inverted: true

  • platform: gpio
    pin: GPIO17
    name: “2”
    id: relay2
    restore_mode: ALWAYS_OFF
    inverted: true

  • platform: gpio
    pin: GPIO18
    name: “3”
    id: relay3
    restore_mode: ALWAYS_OFF
    inverted: true

  • platform: gpio
    name: “4”
    pin: GPIO19
    id: relay4
    restore_mode: ALWAYS_OFF
    inverted: true

  • platform: gpio
    pin: GPIO21
    name: “5”
    id: relay5
    restore_mode: ALWAYS_OFF
    inverted: true

  • platform: gpio
    name: “6”
    pin: GPIO22
    id: relay6
    restore_mode: ALWAYS_OFF
    inverted: true

  • platform: gpio
    pin: GPIO23
    name: “7”
    id: relay7
    inverted: true
    restore_mode: ALWAYS_OFF

  • platform: gpio
    pin: GPIO25
    name: “8”
    id: relay8
    inverted: true
    restore_mode: ALWAYS_OFF

its working after restart homeassistant but can i use same remote button to switch off these relays?

Yes you can. In automation instead of switch.turn_on and switch.turn_off try switch.toggle . This should toggle the switch everytime you press the button.

1 Like