SwitchBot bot/curtain/meter/contact/motion MQTT ESP32 bridge - Local control

I have changed the script to this and mqtt does not read the changes under setHold

  holdpress_bot:
    sequence:
      - service: mqtt.publish
        data:
          topic: 'switchbotmqtt/bot/24hr_fan/set'
          payload: 3

I do not need to enable this setHold in the esp config file correct?

Oh wait, I see, it is not under a folder in the bot’s name. but the bot does not hold the press though.

nothing to do on esp32. but give me a couple min I am working on some minor changes again

I’ll try your scripts after

1 Like

Also in V3, I noticed I can only use switch.turn_on to press the bot. Using `switch.turn_off have no affect in moving the bot.

  action:
    - service: switch.turn_on
      data:
        entity_id: switch.24hr_fan_switch

v3.2 release. I haven’t tried your scripts yet, but I am able to call setHold and immediately after a press command. They will process in order by the esp32

Yes when the switch is in press mode, OFF is disabled/ignored. This is normal. A switch in press mode will always default to state = “OFF”. To do the press action, simply always call the ON command

If you want to manage an ON/OFF switch that controls a press action, you would need to create a separate device. The switchbot has no idea of the ON/OFF state when in press mode

the hold secs value is returned by an automatic requestSettings call that is made right after the hold secs command. You will find the hold secs confirmed value here on the settings topic. HA receiving a message on the settings topic will update the hold secs in HA

 - <ESPMQTTTopic>/bot/<name>/settings
                      Example payloads:
                         - {"firmware":4.9,"timers":0,"inverted":false,"hold":5}

If you want to manage an ON/OFF switch that controls a press action, you would need to create a separate device. The switchbot has no idea of the ON/OFF state when in press mode

oh. I read some comments about this, but didn’t quite understand.

This will still work under V3.2?

Yes I fixed the setHold topic in v3.2, it wasn’t calling the requestSettings after to collect the proper hold secs from the bot.

setting the hold time through the /set topic was properly calling requestSettings, I just missed it in the other topic. Fixed in v3.2

Where you able to get it to work with the setHold? Still not able from my end.
I have tried both of these scripts.

  holdpress_bot:
    sequence:
      - service: mqtt.publish
        data:
          topic: 'switchbotmqtt/setHold'
          payload_template: "{\"id\":\"{{ bot }}\", \"hold\":\"{{ press }}\"}"
  holdpress_bot:
    sequence:
      - service: mqtt.publish
        data:
          topic: 'switchbotmqtt/bot/{{ bot }}/set'
          payload: "{{ press }}"

I am seeing the changes in mqtt.
2021-06-14_13-34-43

yes, it seems to be working fine for me in nodered. I’ll try ur script in a bit. working on a couple things atm

…and you aren’t seeing hold returned here…?

see "hold": 5 in my example

<ESPMQTTTopic>/bot/<name>/settings
                      Example payloads:
                         - {"firmware":4.9,"timers":0,"inverted":false,"hold":5}

this is where the hold is returned after u set it.

the esp32 cant call the press action before it gets this

This is the serial log output.

Control MQTT Received...
Received something on switchbotmqtt/esp32/control
24hr_fan
Processing Control MQTT...
Device: 24hr_fan
Device value: ON
Try to connect. Try a reconnect first...
lld_pdu_get_tx_flush_nb HCI packet count mismatch (1, 2)
Reconnect failed
Connected
Connected to: fa:b6:25:7b:05:e4
RSSI: -79
Sending command...
subscribed to notify
CUSTOM write service not found.
Sending command...
Attempt to send command. Not connecting. Try connecting...
Try to connect. Try a reconnect first...
Connected
Reconnected client
Connected to: fa:b6:25:7b:05:e4
RSSI: -83
subscribed to notify
Wrote new value to: cba20002-224d-11e6-9fb8-0002a5d5c51b
notifyCB
deviceName: WoHand
Success! Command sent/received to/from SwitchBot
The response value from bot action: 5
Done sendCommand...

In the app, do I set it to zero or 3 for my case?

hmmmm… that might not be good

CUSTOM write service not found.

I’m hoping we don’t have different bots.

I am testing the curtain using the position service now and this is in log. but it seems to be working so far. need to play with it some more though.

Control MQTT Received...
Received something on switchbotmqtt/esp32/control
cr_curtain_lt
Processing Control MQTT...
Device: cr_curtain_lt
Device value: 73
Try to connect. Try a reconnect first...
Connected
Connected to: c5:c6:df:94:48:bc
RSSI: -108
Sending command...
lld_pdu_get_tx_flush_nb HCI packet count mismatch (1, 2)
CUSTOM notify service not found.
Sending command...
Attempt to send command. Not connecting. Try connecting...
Try to connect. Try a reconnect first...
Connected
Reconnected client


not sure I understand

In my example use case to turn on/off a pc

To turn on the pc

  1. set the hold time to 0 secs
  2. call the press command

to turn off the pc

  1. set the hold time to 10 secs
  2. call the press command

i think you scripts are correct, but it kay be that we have different model bots. I may need to het the correct BLE service value for your models

once the hold time is set, the bot will remember it in its memory. same as setting it through the switchbot app. the following press actions will use the latest hold time in the bot memory

most likely though our bots are different models with that custom writr service bot found error

In the app, do I set it to zero or 3 for my case?

I mean in t he mobile switchbot app.

once the hold time is set, the bot will remember it in its memory. same as setting it through the switchbot app. the following press actions will use the latest hold time in the bot memory

So it doesn’t matter what the settings in the app is at. If you set a hold time, it will that over the app hold time value?

This hold value is not taken from the app correct? It should read 3 if it is.
2021-06-14_14-11-08

ya the only thing I need the app for now is setting a password on bot

The rest I can do myself

  • mode can be set (press/switch)
  • hold secs can be set
  • timers can be set (but I didn’t write the code since I would use the timer in HA anyways)

switchbot hasn’t release the code for setting passwords, that is all that is missing for bots

they haven’t provided as much for curtains, just the basic control functions. I guessed the rest

You have tested my script and it works for you is that what you said?

HA and the switchbot app show the same hold time for me, whether I set it via the ESP32 or through the switchbot app.

I’ll look if there are different model numbers I can look for

Bummer if you suspect the bot model to be different. The hold timer would be useful for me.

About the Curtain on V3.2.
It seems to be working find now. I was moving the curtain using only the position and it seems to work. I noticed that the position # in HA and the mobile app is reverse.

Position: 100 in HA shows that the curtain is open.
The mobile app position: 100 shows that the curtain is closed.

This image shows the curtain to be open and the position is 2 which is close to zero.

yes this is just how HA works, it is discussed above and in github issues