setting the hold seconds on bots is useful for people that need to use the same bot for different hold times.
Example: turning something on requires holding for 10 seconds, turning that same thing off requires holding for 0 seconds.
I have a device that does just that. I need to hold press for 3 seconds to turn off. A short press to turn on. I tried to follow your example in the V3 release note, but I am not understanding.
publish a value from 0-100 for bot to (just lile position for curtain
<ESPMQTTTopic>/bot/<name>/set
b) publish a message like {"id":"switchbotone", "hold":5} to
<ESPMQTTTopic>/setHold
when hold time is set, the hold time will be retrieved right after
now that hold time is set, you can call a press command and it will hold for the new time you set
you have to set the hold time before the press.
You can set hold time right before the press action, or at anytime before. the bot remembers its hold time and so does the esp32
I should have a fix for this in v3.1. That works nice when the bot is in press mode, but ya in switch mode the state flips back temporarily until it receives a state update from the esp32
it will currently switch to the proper state once the commandSent is received and for good measure also when the individual device scan is performed after a set/control
I am calling this script via automation. Not sure if the delay is needed, but I have tried with and without delay.
- alias: '24hr fan toggle on-off'
trigger:
- platform: time
at: '05:25:00'
- platform: time
at: '23:00:00'
condition:
- condition: template # Someone is Home
value_template: "{{ is_state('input_select.home_mode', 'Home') }}"
action:
- service: >-
{% if is_state( 'sensor.time', '05:25' ) %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
data:
entity_id: switch.24hr_fan
- alias: '24hr fan toggle speed'
trigger:
- platform: state
entity_id: sensor.period_of_the_day
to: 'nightlight'
- platform: time
at: '05:30:00'
condition:
- condition: template # Someone is home
value_template: "{{ is_state('input_select.home_mode', 'Home') }}"
action:
- service: script.holdpress_bot
data:
bot: '24hr_fan'
press: 0
- service: switch.turn_on
data:
entity_id: switch.24hr_fan_switch
Both automation are zero second presses. I am assuming it is from the app I have set to zero.
In MQTT, I can see the setHold and it seems to be taken the hold numbers correctly.
To create a customer switch with hold press. Change to suite to your settings.
switch.yaml
- platform: template
switches:
floor_heater:
friendly_name: 'Floor Heater'
value_template: "{{ states('input_boolean.floor_heat') }}"
turn_on:
- service: script.holdpress_bot
data:
bot: 'floor_heat' # taken from your esp32 bot name
press: 0 # how long you want the press to hold
- service: input_boolean.turn_on
entity_id: input_boolean.floor_heat
turn_off:
- service: script.holdpress_bot
data:
bot: 'floor_heat' # taken from your esp32 bot name
press: 3 # how long you want the press to hold
- service: input_boolean.turn_off
entity_id: input_boolean.floor_heat
icon_template: >-
{% if is_state('input_boolean.floor_heat', 'on') %}
mdi:check-circle
{% else %}
mdi:check-circle-outline
{% endif %}
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.
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...
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
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