Here is how I control my bot and curtain devices. The script is basically a template that will be call from your xx amount of curtain or bot devices. Each time you call your bot, it will also update the data info in mqtt.
Switchbot Bot
This should cover for xx amount of bots you have setup. You only need to create the script.yaml once.
For the switch.yaml, create one for how ever many bots you have changing the bot
name. Some goes with the input_boolean.yaml.
The delay was trial and error on my part. Adjust to your liking.
Note: I have changed the MQTT topic to all lower caps. You will need to edit that if you left as is.
Update: As of v.19+, we no longer need to maunally call requestInfo
to update the bot data. I have removed what is not needed any longer.
script.yaml
enable_bots_tpl:
sequence:
- service: mqtt.publish
data:
topic: 'switchbotmqtt/control'
payload_template: "{\"id\":\"{{ bot }}\", \"value\":\"press\"}"
switchbot_update_device:
sequence:
- service: mqtt.publish
data:
topic: 'switchbotmqtt/requestInfo'
payload_template: "{\"id\":\"{{ bot }}\"}"
switch.yaml
- platform: template
switches:
24h_fan:
friendly_name: '24h Fan'
value_template: "{{ states('input_boolean.washroom_fan') }}"
turn_on:
- service: script.enable_bots_tpl
data:
bot: '24hr_fan'
- service: input_boolean.turn_on
entity_id: input_boolean.washroom_fan
turn_off:
- service: script.enable_bots_tpl
data:
bot: '24hr_fan'
- service: input_boolean.turn_off
entity_id: input_boolean.washroom_fan
icon_template: >-
{% if is_state('input_boolean.washroom_fan', 'on') %}
mdi:fan
{% else %}
mdi:fan-off
{% endif %}
input.boolean.yaml
washroom_fan:
name: Washroom Fan
icon: mdi:fan
Curtain Bot
Create one script for each curtain devices you have. This script will work for open, close, stop, & position. The delay was trial and error on my part. Adjust to your liking.
script.yaml
enable_cr_curtains_tpl:
sequence:
- service: mqtt.publish
data:
topic: 'switchbotmqtt/control'
payload_template: "{\"id\":\"{{ bot }}\", \"value\":\"{{ modus }}\"}"
### If you are onlying running one device for your curtain and not a combo, you can delete the below. Otherwise, change the bot name to your second device. ###
- delay: 15
- service: script.switchbot_update_device
data_template:
bot: 'cr_curtain_rt'
cover.yaml
- platform: template
covers:
computer_room_curtain:
device_class: curtain
friendly_name: "Computer Room Curtain"
value_template: >-
{% if states('sensor.cr_curtain_left_position')|float < 90 %}
open
{% else %}
closed
{% endif %}
open_cover:
service: script.enable_cr_curtains_tpl
data:
modus: "open"
bot: 'cr_curtain_lt'
close_cover:
service: script.enable_cr_curtains_tpl
data:
modus: "close"
bot: 'cr_curtain_lt'
stop_cover:
service: script.enable_cr_curtains_tpl
data:
modus: "pause"
bot: 'cr_curtain_lt'
set_cover_position:
service: script.enable_cr_curtains_tpl
data:
modus: "{{ position }}"
bot: 'cr_curtain_lt'
icon_template: >-
{% if is_state('cover.computer_room_curtain', 'open') %}
mdi:blinds-open
{% else %}
mdi:blinds
{% endif %}
sensor.yaml
- platform: mqtt
name: "CR Curtain Left Position"
state_topic: 'switchbotmqtt/curtain/cr_curtain_lt'
value_template: '{{ value_json.serviceData.pos }}'
unit_of_measurement: "%"
icon: mdi:format-list-numbered