• Also what are you using as an esphome bridge? A smartplug or similar?

    It's a mix - I have a SONOFF thing wired in upstairs which does the hall light, and that runs it - but it wouldn't reach.

    So then I just used an ESP32 board I had kicking around (something like https://www.amazon.co.uk/ESP-32S-Development-2-4GHz-Bluetooth-Antenna/dp/B071JR9WS9/ref=sr_1_3) and stuck it in the TV cabinet, powered off the USB supply I use for my Google TV.

    I think Tasmota will do the bridge too? https://tasmota.github.io/docs/Bluetooth_MI32/ But I'm not sure as I've never used it.

    For advertising, I actually mean:

    function updateAdvertising() {
      NRF.setAdvertising(require("BTHome").getAdvertisement([
        {
          type : "battery",
          v : E.getBattery()
        },
        {
          type : "temperature",
          v : E.getTemperature()
        }
      ]), { name : "Sensor1", interval:20 }); // <---- here
    }
    

    And keep your setInterval the same. It will use more power, but you can for instance do this, based on the code lower down https://www.espruino.com/BTHome:

    var buttonState = false;
    var slowTimeout;
    
    function updateAdvertising() {
      NRF.setAdvertising(require("BTHome").getAdvertisement([
        {
          type : "battery",
          v : E.getBattery()
        },
        {
          type : "temperature",
          v : E.getTemperature()
        },
        {
          type: "button_event",
          v: buttonState ? "press" : "none"
        },
      ]), { name : "Sensor1", interval: buttonState?20:2000 });
      if (slowTimeout) clearTimeout(slowTimeout);
      slowTimeout = setTimeout(function() { 
        slowTimeout = undefined;
        updateAdvertising();
      }, 60000);
      // ensure that subsequent updates show button is not pressed
      buttonState = false;
    }
    // When a button is pressed, update advertising with the event
    setWatch(function() {
      buttonState = true;
      updateAdvertising();
    }, BTN, {edge:"rising", repeat:true})
    
    updateAdvertising();
    NRF.setTxPower(4);
    

    So now, when you press the button it should start advertising quick, but only for 60 seconds while it's advertising a button press, and then it'll go back to being slow (and will still update every 60 seconds).

About

Avatar for Gordon @Gordon started