Send RF signal when reed switch opens

Almost got this nailed down, but now just struggling to send the RF signal when the reed is opened.

The objective is simply when the reed switch is closed, deep sleep is entered. When the reed switch open, wake from deep sleep and send the code with the RF 433mhz transmitter.

Trying to use the on_press function for this but it does not like it.

Also, I may need a delay to send when waking from deep_sleep?

Any ideas?

Thanks

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO27
      mode:
        input: True
        pullup: True
      inverted: False
      allow_other_uses: True 
    name: mail
    filters:
      - delayed_on: 25ms
      - delayed_off: 500ms
    on_press:
      then:
      - platform: remote_receiver
        name: Garage
          raw:
        code: [415,-300,370,-300,375,-300,378,-300,378,-300,379,-300,405]
    on_release:
      then:
      # switch relais? 
      # led blink with repeat action etc?
      # delay to complete
      - deep_sleep.enter: mail



deep_sleep:
  id: mail
  #run_duration: 2min
  #sleep_duration: 1min
  wakeup_pin:
      number: GPIO27
      allow_other_uses: True

sensor:
  - platform: custom
    lambda: |-
      auto my_sensor = new CC1101(
        18, // SCK
        19, // MISO
        23, // MOSI
        5, // CSN
        32, // GDO0
        33, // GDO2
        200, // bandwidth_in_khz
        433.92 // freq_in_mhz
      );
      App.register_component(my_sensor);
      return {my_sensor};
    sensors:
      id: transciver
      internal: true
remote_transmitter:
  - pin: GPIO32 # This is GDO0
    carrier_duty_percent: 100%

remote_receiver:
  - pin: GPIO33 # This is GDO2
      # on the esp8266 use any of D1,D2,D5,D6,D7,Rx
      # Don't use D3,D4,D8,TX, boot often fails.
      # Can't be D0 or GPIO17 b/c no interrupts
    dump:
      - raw

button:
  - platform: template
    name: Garage
    on_press:
      - lambda: get_cc1101(transciver).beginTransmission();
      - remote_transmitter.transmit_raw:
          code: [415,-300,370,-300,375,-300,378,-300,378,-300,379,-300,405]
          repeat: 
            times: 10
            wait_time: 10ms
      - lambda: get_cc1101(transciver).endTransmission();

Why not just run an automation when the state changes? Sleep or wake wouldn’t matter unless the device you’re using to transmit RF is also the device that goes to sleep, which you’d need to keep the device awake.

How about an on_boot: trigger coupled with a check for the right wake_cause?

You may need to add a delay of some kind of wait_until condition to give things time to initialise.

Or alternatively, maybe just add an on_value trigger to the wakeup_cause sensor?

The device will not have wifi connection when finalised.

It will not connect to home assistant.

Ok, i’ve come up with this, however it still will not send the command when it wakes from deep_sleep?

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO27
      mode:
        input: True
        pullup: True
      inverted: False
      allow_other_uses: True 
    name: mail
    filters:
      - delayed_on: 25ms
      - delayed_off: 500ms
    on_press:
      - delay: 10s
      - lambda: get_cc1101(transciver).beginTransmission();
      - remote_transmitter.transmit_raw:
          code: [415,-300,370,-300,375,-300,378,-300,378,-300,379,-300,405]
          repeat: 
            times: 10
            wait_time: 10ms
      - lambda: get_cc1101(transciver).endTransmission();
    on_release:
      then:
      # switch relais? 
      # led blink with repeat action etc?
      # delay to complete
      - deep_sleep.enter: mail

I think the problem is that it only triggers when the reed switch goes from closed to open. Your reed is already open when the device wakes as you use it to wake the device. Did the suggestion from @ Mahko_Mahko to send the signal on boot not work? Have you been able to send the signal at any stage when the device has be awake i.e. when deep sleep disabled?

Yea I actually have,

It seems a bit hit and miss, but it has sent the signal occasionally, however, it takes a while (like 30 seconds). This will be no good for me as the letterbox will have been opened and already closed by then.

I will try the on_boot.

Also, do you know how I can disable WiFi on esphome, I don’t need wifi on the transmitter and I think it is delaying the bootup. Also, it will not find a wifi network when booting so its useless, I can save power and maybe cut down the boot time.

Thanks

Ok, the on_boot function actually works pretty well,

I also added a delay to enter deep sleep of 10s to allow the signal to be sent, this seems to work well.

Is it also possible now to send a restore when closed before entering deep_sleep?

Something like,

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO27
      mode:
        input: True
        pullup: True
      inverted: False
      allow_other_uses: True 
    name: mail
    filters:
      - delayed_on: 25ms
      - delayed_off: 500ms
    on_release:
      - lambda: get_cc1101(transciver).beginTransmission();
      - remote_transmitter.transmit_raw:
          code: [415,-300,370,-300,375,-300,378,-300,378,-300,379,-300,405]
          repeat: 
            times: 10
            wait_time: 10ms
      - lambda: get_cc1101(transciver).endTransmission();
      then:
      # switch relais? 
      # led blink with repeat action etc?
      # delay to complete
      - delay: 10s
      - deep_sleep.enter: mail

But this doesnt seem to work. Doesnt like it

If you can’t connect by wifi perhaps an ESP device is excess to requirement.


This is what I use. I removed the reed switch and put in in mailbox. The 433mhz door sensor is put in a waterproof box on the side of the mailbox facing the receiver in the house. Main problem was just keeping the sensor waterproof. It reports when mail flap opened and then closed. It reports quicker than an ESP could boot up and lasts more than a year on a AAA cell.

1 Like

I could do,

I don’t have any current RF in my environment, So I need to put in a receiver too. Obviously I am using the CC1101 which is a transceiver. Can this be used to receive the RF signals from a device such as your picture above?

Thanks

Most likely.

You can build something like this if you like.

Ok thanks, Ive got some 433mhz remotes that I have soldered a reed switch on the push button, how can I read these codes and know what codes to put in my receiver?

Thanks

OMGateway

Yes, the cc1101 works well in the OpenMqttGateway. The OMG is then discovered by HA. It will publish mqtt messages to HA for your 433 devices. You will need to set up mqtt on HA.

Maybe I’m missing something here about your cc1101 set-up but can’t you just see what shows up in the esp remote_reciever logs when you activate the transmitters?

Yea maybe, I just wasn’t sure if the RAW codes were like encoded or something?

So what you see is what’s sent?

Can you explain more on the cc1101 and OMG, I haven’t seen this and this might be a better way to do things.

Yes. If you dump all: then decoded codecs like rc_switch will show up in the logs.

Raw is handy for arbitrary protocols.

My experience is that most cheap rf devices are pretty straight forward to capture codes.

1 Like

OK thanks.

For some reason, I am unable to flash openmqttgateway using the web flasher.

Is there a bug? It does not work. The serial popup does not show up at all.