ESPHome IR Switch

Hey all. I have an infrared cooktop and an infrared extractor fan. I want to implement a gateway that will receive a command from the hob and transmit a clear command to turn on the hood. there is this code

binary_sensor:
  - platform: remote_receiver
    name: "TEST_LAMP1"
    id: TEST_LAMP1
    raw:
      code: [755, -1404, 704, -763, 1453, -680, 785, -1349, 704, -763, 1424, -2818, 729, -709, 732, -736, 1451]
    on_press:
      then:
        - switch.turn_on: TEST_LAMP

switch:
  - platform: template
    id: TEST_LAMP
    name: "TEST_LAMP"
    restore_mode: ALWAYS_OFF
    turn_on_action:
     - remote_transmitter.transmit_raw:
          code: [1345, -1683, 1323, -1682, 1324, -1681, 1320, -5719, 1348, -1683, 1319, -1683, 1321, -1683, 1319, -1687, 1317]
          repeat:
              times: 5
              wait_time: 16ms
          carrier_frequency: 38kHz

the switch is created in HA and if I turn it on with my hands everything is ok. but if I try to turn on the hood from the hob, the switch in the HA interface does not turn on, and the hood turns on and off. the hood has the same command to turn it on and off. so I planned to use a virtual switch. tell me what i’m wrong

What happens if you change 5 to 1?

this value does not really affect (I tried to completely remove it. I can’t figure out why the switch in HA does not go into the on state when receiving a signal from the hob. I think this would solve all the problems

Can you see the relevant triggers and actions happening in the ESPHome logs?

Have you tried optimistic:true?

1 Like

I’m attaching the logs below. The parameter helped, the switch began to turn on, but sending commands to the hood seemed to go in parallel. I see in the interface that the switch is on, and according to my logic, in this state, the command should not send switches, since it is on, but the light still turns on and off (((

[10:22:30][D][binary_sensor:036]: 'TEST_LAMP1': Sending state ON
[10:22:30][D][switch:012]: 'TEST_LAMP' Turning ON.
[10:22:30][D][remote_transmitter:075]: Sending remote code...
[10:22:31][D][switch:055]: 'TEST_LAMP': Sending state ON
[10:22:31][D][binary_sensor:036]: 'TEST_LAMP1': Sending state OFF
[10:22:31][D][remote.raw:041]: Received Raw: 1372, -1664, 1338, -1667, 1338, -1666, 1339, -5698, 1366, -1668, 1338, -1664, 1338, -1667, 1337, -1668, 1338
[10:22:31][D][remote.raw:041]: Received Raw: 1385, -1665, 1338, -1666, 1338, -1668, 1337, -5679, 1386, -1644, 1361, -1663, 1338, -1646, 1358, -1669, 1336
[10:22:31][D][remote.raw:041]: Received Raw: 1362, -1641, 1361, -1667, 1338, -1667, 1338, -5674, 1391, -1667, 1338, -1664, 1338, -1666, 1337, -1670, 1337
[10:22:31][D][remote.raw:041]: Received Raw: 1385, -1664, 1338, -1667, 1339, -1667, 1336, -5677, 1389, -1667, 1338, -1664, 1337, -1668, 1338, -1668, 1337
[10:22:31][D][remote.raw:041]: Received Raw: 1385, -1664, 1337, -1668, 1338, -1646, 1359, -5679, 1386, -1667, 1338, -1664, 1337, -1645, 1360, -1645, 1362
[10:22:31][D][binary_sensor:036]: 'TEST_LAMP1': Sending state ON
[10:22:31][D][switch:012]: 'TEST_LAMP' Turning ON.
[10:22:31][D][remote_transmitter:075]: Sending remote code...
[10:22:31][D][binary_sensor:036]: 'TEST_LAMP1': Sending state OFF
[10:22:31][D][remote.raw:041]: Received Raw: 1355, -1664, 1338, -1667, 1337, -1669, 1337, -5676, 1388, -1667, 1340, -1663, 1338, -1667, 1337, -1644, 1362
[10:22:31][D][remote.raw:041]: Received Raw: 1383, -1665, 1337, -1668, 1338, -1667, 1337, -5677, 1389, -1667, 1338, -1664, 1338, -1665, 1338, -1669, 1337
[10:22:31][D][remote.raw:041]: Received Raw: 1362, -1640, 1362, -1668, 1337, -1667, 1339, -5675, 1389, -1643, 1361, -1666, 1337, -1666, 1338, -1669, 1337
[10:22:32][D][remote.raw:041]: Received Raw: 1386, -1664, 1339, -1667, 1337, -1666, 1340, -5675, 1389, -1668, 1337, -1664, 1340, -1641, 1362, -1666, 1339
[10:22:32][D][remote.raw:041]: Received Raw: 1385, -1639, 1363, -1644, 1360, -1644, 1363, -5674, 1390, -1667, 1339, -1664, 1337, -1666, 1337, -1670, 1337
[10:22:32][D][binary_sensor:036]: 'TEST_LAMP1': Sending state ON
[10:22:32][D][switch:012]: 'TEST_LAMP' Turning ON.
[10:22:32][D][remote_transmitter:075]: Sending remote code...
[10:22:32][D][binary_sensor:036]: 'TEST_LAMP1': Sending state OFF
[10:22:32][D][remote.raw:041]: Received Raw: 1378, -1665, 1337, -1667, 1338, -1644, 1361, -5702, 1363, -1667, 1338, -1664, 1338, -1666, 1338, -1642, 1366
[10:22:32][D][remote.raw:041]: Received Raw: 1383, -1641, 1360, -1668, 1338, -1667, 1338, -5677, 1389, -1666, 1338, -1664, 1337, -1667, 1337, -1670, 1339
[10:22:32][D][remote.raw:041]: Received Raw: 1387, -1664, 1339, -1667, 1337, -1667, 1313, -5703, 1387, -1668, 1336, -1664, 1339, -1666, 1337, -1670, 1337
[10:22:33][D][remote.raw:041]: Received Raw: 1386, -1664, 1338, -1667, 1338, -1667, 1337, -5682, 1383, -1667, 1339, -1665, 1337, -1666, 1338, -1668, 1338
[10:22:33][D][remote.raw:041]: Received Raw: 1385, -1664, 1338, -1667, 1338, -1644, 1361, -5677, 1388, -1666, 1339, -1663, 1338, -1666, 1340, -1668, 1336
[10:22:49][D][remote.raw:041]: Received Raw: 207

it looks like the pull signal is sent when a command is received

[10:22:32][D][switch:012]: 'TEST_LAMP' Turning ON.

but you probably need to do it when changing the status from off to on

I think I got it. in place of turn_on_action: need to use on_turn_on:
in this case the signal is sent 1 time under the assumption that the switch is in the off state

1 Like