Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 5,369
» Latest member: talljane
» Forum threads: 2,574
» Forum posts: 13,305

Full Statistics

Online Users
There are currently 44 online users.
» 0 Member(s) | 28 Guest(s)
AhrefsBot, Bing, Bytespider, Crawl, Go-http-client, Google, PetalBot, bot

Latest Threads
KC868-A2 ESP32 I/O pin de...
Forum: KC868-A2
Last Post: tugra
3 hours ago
» Replies: 7
» Views: 2,261
change wake up name
Forum: KinCony AS
Last Post: gal
11 hours ago
» Replies: 12
» Views: 78
A32 Pro ESPHome yaml incl...
Forum: KC868-A32/A32 Pro
Last Post: xarouli5
Today, 06:38 AM
» Replies: 17
» Views: 181
Need help with configurat...
Forum: KC868-HxB series Smart Controller
Last Post: admin
Today, 04:32 AM
» Replies: 32
» Views: 393
ESP32 S3 set up issue
Forum: Extender module
Last Post: admin
Yesterday, 11:43 PM
» Replies: 10
» Views: 66
KC868-A8 Schematic
Forum: KC868-A8
Last Post: admin
Yesterday, 11:40 PM
» Replies: 7
» Views: 49
"KCS" v2.2.8 firmware BIN...
Forum: "KCS" firmware system
Last Post: admin
Yesterday, 11:38 PM
» Replies: 2
» Views: 172
Dimensions/drawings of bo...
Forum: Schematic and diagram
Last Post: admin
Yesterday, 11:37 PM
» Replies: 1
» Views: 23
how to use AS ESP32-S3 vo...
Forum: KinCony AS
Last Post: admin
12-16-2024, 10:55 PM
» Replies: 12
» Views: 448
Problem with IFTTT automa...
Forum: "KCS" firmware system
Last Post: admin
12-16-2024, 10:53 PM
» Replies: 5
» Views: 34

  [Arduino demo source code for KC868-A4]-14 MQTT demo
Posted by: admin - 04-19-2022, 12:47 AM - Forum: KC868-A4 - Replies (18)

Code:
// MQTT demo source code for KC868-A4
// Remote control relay ON/OFF by any MQTT broker
// Digital input use by switch button for ON/OFF and demo show state feedback
// You can use by MQTTBOX for test or KinCony KBOX android phone app

#define Relay1  2
#define Relay2  15
#define Relay3  5
#define Relay4  4

#define Key1  36
#define Key2  39
#define Key3  27
#define Key4  14


int KEY_NUM1 = 0;    //key_1 value
int KEY_NUM2 = 0;    //key_2 value
int KEY_NUM3 = 0;    //key_3 value
int KEY_NUM4 = 0;    //key_4 value

#include <string.h>
#include <WiFi.h>
#include <PubSubClient.h>


// WiFi
const char *ssid = "KinCony"; // Enter your WiFi name
const char *password = "a12345678";  // Enter WiFi password

// MQTT Broker
const char *mqtt_broker = "iot.kincony.com";  // or your MQTT broker IP/Domain
const char *topic_command = "relay4/123456/set";  // if use by KBOX android phone app, use relay4/xxxxxx/set      for command
const char *topic_state = "relay4/123456/state";  // if use by KBOX android phone app, use relay4/xxxxxx/state    for feedback state
const char *mqtt_username = "mqtt";
const char *mqtt_password = "123";
const int mqtt_port = 1883;

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {

  pinMode(Relay1,OUTPUT);   //Relay1 IO2
  pinMode(Relay2,OUTPUT);   //Relay2 IO15
  pinMode(Relay3,OUTPUT);   //Relay3 IO2
  pinMode(Relay4,OUTPUT);   //Relay4 IO2

  pinMode(Key1,INPUT);  //Digital input1 IO36
  pinMode(Key2,INPUT);  //Digital input2 IO39
  pinMode(Key3,INPUT);  //Digital input3 IO27
  pinMode(Key4,INPUT);  //Digital input4 IO14

  pinMode(2, OUTPUT);   //relay1
  pinMode(15, OUTPUT);  //relay2
  pinMode(4, OUTPUT);   //relay3
  pinMode(5, OUTPUT);   //relay4

  digitalWrite(2, LOW);   // turn the LED OFF (HIGH is the voltage level)
  digitalWrite(15,LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);

 
// Set software serial baud to 115200;
Serial.begin(115200);
// connecting to a WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
     delay(500);
     Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
//connecting to a mqtt broker
client.setServer(mqtt_broker, mqtt_port);
client.setCallback(callback);
while (!client.connected()) {
     String client_id = "esp32-client-";
     client_id += String(WiFi.macAddress());
     Serial.printf("The client %s connects to the public mqtt broker\n", client_id.c_str());
     if (client.connect(client_id.c_str(), mqtt_username, mqtt_password)) {
         Serial.println("Public emqx mqtt broker connected");
     } else {
         Serial.print("failed with state ");
         Serial.print(client.state());
         delay(2000);
     }
}
// publish and subscribe
client.publish(topic_state, "Hi I am KC868-A4");
client.subscribe(topic_command);
}

void callback(char *topic_command, byte *payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic_command);
Serial.print("Message:");
for (int i = 0; i < length; i++) {
     Serial.print((char) payload[i]);
}
Serial.println();
Serial.println("-----------------------");

if (!strncmp((char *)payload, "{\"relay1\":{\"on\":1}}", length)) digitalWrite(Relay1, HIGH);
else if (!strncmp((char *)payload, "{\"relay1\":{\"on\":0}}", length)) digitalWrite(Relay1, LOW);

if (!strncmp((char *)payload, "{\"relay2\":{\"on\":1}}", length)) digitalWrite(Relay2, HIGH);
else if (!strncmp((char *)payload, "{\"relay2\":{\"on\":0}}", length)) digitalWrite(Relay2, LOW);

if (!strncmp((char *)payload, "{\"relay3\":{\"on\":1}}", length)) digitalWrite(Relay3, HIGH);
else if (!strncmp((char *)payload, "{\"relay3\":{\"on\":0}}", length)) digitalWrite(Relay3, LOW);

if (!strncmp((char *)payload, "{\"relay4\":{\"on\":1}}", length)) digitalWrite(Relay4, HIGH);
else if (!strncmp((char *)payload, "{\"relay4\":{\"on\":0}}", length)) digitalWrite(Relay4, LOW);



if (!strncmp((char *)payload, "{\"relay4\":{\"read\":1}}", length)) {   //for app read all state, replace with your read relay and input code
      client.publish(topic_state, "{\"relay1\":{\"on\":0},\"relay2\":{\"on\":0},\"relay3\":{\"on\":0},\"relay4\":{\"on\":0},\"input1\":{\"on\":0},\"input2\":{\"on\":0},\"input3\":{\"on\":0},\"input4\":{\"on\":0}}");
    }


}

void loop() {
  ScanKey1();            //scan key1
  ScanKey2();            //scan key2
  ScanKey3();            //scan key3
  ScanKey4();            //scan key4
client.loop();
}

void ScanKey1()           
{
  String temp="{\"relay1\":{\"on\":";

  KEY_NUM1 = 0;                     
  if(digitalRead(Key1) == LOW)         //key1 pressed
  {
    delay(20);                        //anti-interference
    if(digitalRead(Key1) == LOW)       //key1 pressed again
    {
      KEY_NUM1 = 1;                  
      while(digitalRead(Key1) == LOW); //wait remove hand
    }
  }
  if(KEY_NUM1 == 1)              //if key1 pressed
  {  
    digitalWrite(Relay1,!digitalRead(Relay1));    // toggle relay1 state
    if(digitalRead(Relay1) == LOW) temp=temp+"0}}";
    if(digitalRead(Relay1) == HIGH) temp=temp+"1}}";

    client.publish(topic_state, temp.c_str());
  } 
}

void ScanKey2()           
{
  String temp="{\"relay2\":{\"on\":";
  KEY_NUM2 = 0;                     
  if(digitalRead(Key2) == LOW)         //key2 pressed
  {
    delay(20);                        //anti-interference
    if(digitalRead(Key2) == LOW)       //key2 pressed again
    {
      KEY_NUM2 = 1;                  
      while(digitalRead(Key2) == LOW); //wait remove hand
    }
  }
  if(KEY_NUM2 == 1)              //if key2 pressed
  {  
    digitalWrite(Relay2,!digitalRead(Relay2));    // toggle relay2 state
    if(digitalRead(Relay2) == LOW) temp=temp+"0}}";
    if(digitalRead(Relay2) == HIGH) temp=temp+"1}}";
    client.publish(topic_state, temp.c_str());
  }
}

void ScanKey3()           
{
  String temp="{\"relay3\":{\"on\":";
  KEY_NUM3 = 0;                     
  if(digitalRead(Key3) == LOW)         //key3 pressed
  {
    delay(20);                        //anti-interference
    if(digitalRead(Key3) == LOW)       //key3 pressed again
    {
      KEY_NUM3 = 1;                  
      while(digitalRead(Key3) == LOW); //wait remove hand
    }
  }
  if(KEY_NUM3 == 1)              //if key3 pressed
  {  
    digitalWrite(Relay3,!digitalRead(Relay3));    // toggle relay3 state
    if(digitalRead(Relay3) == LOW) temp=temp+"0}}";
    if(digitalRead(Relay3) == HIGH) temp=temp+"1}}";
    client.publish(topic_state, temp.c_str());
  }
}

void ScanKey4()           
{
  String temp="{\"relay4\":{\"on\":";
  KEY_NUM4 = 0;                     
  if(digitalRead(Key4) == LOW)         //key4 pressed
  {
    delay(20);                        //anti-interference
    if(digitalRead(Key4) == LOW)       //key4 pressed again
    {
      KEY_NUM4 = 1;                  
      while(digitalRead(Key4) == LOW); //wait remove hand
    }
  }
  if(KEY_NUM4 == 1)              //if key4 pressed
  {  
    digitalWrite(Relay4,!digitalRead(Relay4));    // toggle relay4 state
    if(digitalRead(Relay4) == LOW) temp=temp+"0}}";
    if(digitalRead(Relay4) == HIGH) temp=temp+"1}}";
    client.publish(topic_state, temp.c_str());
  }
}
   

.zip   a4-mqtt.zip (Size: 2.05 KB / Downloads: 400)

Print this item

  Lesson17 - integrate USB local camera to home assistant
Posted by: admin - 04-18-2022, 12:52 AM - Forum: Home automation training courses - No Replies


1. connect with your USB camera.
2. Enable home assistant "Advanced Mode".
3. "Add-ons, Backups & Supervisor" -- "system" -- "Host" -- "Hardware" ,  search videox
4. Configuration edit yaml
camera:
  - platform: ffmpeg
    name: cam
    input: /dev/input/video0
5. Home assistant restart
6. Add camera to dashboard by "picture entity" card

Print this item

  KC816-A16 ESPHome modbus.
Posted by: aamelkin - 04-16-2022, 06:37 AM - Forum: KC868-A16 - Replies (8)

Hi all, i'm tring to connect r4dcb08 module (https://aliexpress.ru/item/1005002616932...1413511247) to the A16 board using ESPHome
Could you please share me some working config (demo config) for A16 board with some modbus device ? (Existing demo codes havn't modbus examles)
Thanks.

Print this item

  Read 4 channel analog inputs by TCP or RS485 protocol
Posted by: admin - 04-15-2022, 03:25 AM - Forum: KC868-Server Raspberry Pi4 local server - Replies (2)

1: Read 4 channel analog inputs by TCP command:
Send: RELAY-GET_AI-255
Feedback: RELAY-AI-ALL,A0,A1,A2,A3,OK

A0,A1 analog input range: DC0-5V
A2,A3 analog input range: 4-20mA

example:
A0 and A1 connect with 3.3V , will feedback:
RELAY-AI-ALL,330,330,0,0,OK

A2 and A3 connect with 10mA sensor , will feedback:
RELAY-AI-ALL,0,0,455,455,OK


--------------------------------------------------------------
2: enable/disable analog inputs by TCP command:
Send: RELAY-AI_REPORT-255,1    //Enable analog input AUTO feedback
Feedback: RELAY-AI_REPORT-255,1,OK

Send: RELAY-AI_REPORT-255,0   //Disable analog input AUTO feedback
Feedback: RELAY-AI_REPORT-255,0,OK


---------------------------------------------------------------
3. Read 4 channel analog inputs by MODBUS RS485

01 03 01 2C 00 04 CRCH CRCL   
Feedback: 01 03 08 A0 A1 A2 A3 CRCH CRCL

01:RS485 address ID
01 2C=300 register address
00 04 register number

example:
if A0 connect with 3.29V
Send: 01 03 01 2C 00 04 84 3C
Feedback: 01 03 08 01 49 00 00 00 00 00 00 8C DF
01 49 =329 = 3.29V

if A1 connect with 3.31V
Send: 01 03 01 2C 00 04 84 3C
Feedback: 01 03 08 00 00 01 4B 00 00 00 00 30 08
01 4B =331 = 3.31V

Print this item

  KC868-Server V1.48 new firmware update
Posted by: admin - 04-15-2022, 02:21 AM - Forum: News - Replies (13)

improvement:

add manufactory test commands for RS232

command-1 for set to test mode:
    set static IP:192.168.1.200 for ethernet
    set wifi work mode=TCP Server
    set ethernet work mode=TCP Server
    enable 4 chanenl analog input auto report
    set board RS485 address=1
    set board RS485 Baud rate=9600bps

command-2 for Restore factory settings:
    set wifi work mode=UDP
    set ethernet work mode=UDP
    disable 4 channel analog input auto report


.zip   KC868_SERVER_V148_220413.zip (Size: 54.15 KB / Downloads: 374)
download the ZIP file , unzip update the bin file for KC868-H32B relay controller by USB-RS232 cable or ethernet cable.

Print this item

  KC868-Server User Guide Online
Posted by: admin - 04-15-2022, 01:56 AM - Forum: KC868-Server Raspberry Pi4 local server - Replies (8)

[b]1.Diagram of relay Controller[/b]
[Image: KC868-Server2_02.png]
Download PDF details
[b]Leds status different color means:[/b]
Red: Controller is power on.
Green: WiFi module is connect to your router successfully.
White: network run in “TCP Client” mode or “MQTT” mode.
Yellow: network run in “TCP Server” mode.
Blue: network run in “UDP” mode.
[b]what’s UDP , TCP Server, TCP Client, MQTT means:[/b]
When set to “UDP” and set the cloud server IP and port, controller will auto connect to KinCony’s Cloud server. Then you can use “KinCony Smart Home” phone app for remote control relay.
When set to “TCP Server”, controller own is a server work in local network ,you can use “KBOX” phone app without internet and our cloud server to control relay in local network.just your mobile phone or PC and controller connect with same router.
When set to “TCP Client” and set the server IP and port, controller will auto connect to your own server (not KinCony’s cloud server) by “TCP Client”, you can write program for server and make your own phone app to use, this for developer to use.
When set to “MQTT” and set the server IP and port, controller will auto connect to KinCony’s MQTT cloud server or your own server (not KinCony’s cloud server) by MQTT, you can write program for server and make your own phone app to use, this for developer to use. Or you can use “KBOX” android phone app for remote control.
[b]what’s buttons function:[/b]
Button1 “WiFi Reset” : Reset WiFi module, then controller will be work as “AP” mode, you will see the wifi signal “LPT230” for use.Now you can config the ssid and password for your router.
Button2 “Ethernet Mode” : change ethernet work mode for UDP->TCP Server->TCP Client.
Button3 “WiFi Mode” : change WiFi work mode for UDP->TCP Server->TCP Client.
[b]How to use buttons:[/b]
[b]Button1 “WiFi Reset” :[/b] Hold on the button for 5 seconds,then restart power of controller.
[b]Button2 “Ethernet Mode” :[/b]
Hold on the button until LED color changed. There are 5 status:
a.) Hold on button, when the [yellow LED] is ON, release it, then work mode in “TCP server” mode;
b.) Hold on button, when the [white LED] is ON, release it, then work mode in “TCP Client” mode;
c.) Hold on button, when the [blue LED] is ON, release it, then work mode in “UDP” mode;
d.) Hold on button, when the [yellow and white LED] all is ON, release it, then work mode in “UDP” and IP by DHCP mode;
e.) Hold on button, when the [yellow and white and blue LED] all is ON, release it, then work mode in “TCP Server” and IP (192.168.1.200) by static mode;
Note: after changed mode, the controller will restart automatically.
The controller default work mode is DHCP and UDP mode.
[b]Button3 “WiFi Mode” :[/b]
Hold on the button until LED color changed. There are 3 status:
a.) Hold on button, when the [yellow LED] is ON, release it, then work mode in “TCP server” mode;
b.) Hold on button, when the [white LED] is ON, release it, then work mode in “TCP Client” mode;
c.) Hold on button, when the [blue LED] is ON, release it, then work mode in “UDP” mode;
Note: after changed mode, the controller will restart automatically.
The controller default work mode is DHCP and UDP mode.
[b]2.Network Setting[/b]
A.WiFi config (if you use ethernet cable, you can skip WiFi config step):
B.Set Work Mode for remote control (Need internet and KinCony’s cloud server)
C.Set Work Mode for local LAN control (without internet)



[b]A-1.use Ethernet port to config IP and different work mode by “KinCony-SCAN_Device Tool” for KC868-xB/xBS” series (Recommend)[/b]
Let your KinCony smart controller connect to your router by ethernet cable (CAT5) and your computer also connect with your same router, download “KinCony-SCAN_Device Tool” and unzip file, open “KinCony-SCAN_Device.exe”
[Image: ip-scan-1.png]
[Image: kc868-server.png]
Step1: chose your network device of your computer.
Step2: click “StartMonitorPort” button.
Step3: click “SCAN” button.
Now all KinCony Controller (KC868-HxB or KC868-HxBS) will be see. You will see the device IP,Port,UID,type.
[Image: kc868-server-login.png]
web browser login with your KC868-Server’s IP Address, user and password default all are : admin    admin
[Image: kc868-server-control-panel.png]
Here is “Relay Control” panel webpage, you can control every channel output independently.
[Image: Network-Setting-size-small.png]
Here is network setting details.
[b]SSID and password:[/b] These are your router’s.
[b]Work Mode:[/b]
1- UDP: Connect with KinCony Cloud server by internet, you can use “KinCony Smart Home ” mobile phone application.
2- TCP Server: Work in local network without internet, you can use “KBOX” mobile phone application.
3- TCP Client: This mode for programmer or developer, controller can connect to your own cloud server by TCP socket connection.
4- MQTT: Connect to any MQTT broker by IP and Port.
[b]Domain name:[/b] connnect to cloud server by domain name, KC868-Server will use DNS to find IP address for cloud server
[b]Post Password:[/b] for http command line use
[b]SW trigger output:[/b] 16 channel output action link or unlink with 16 channel input
[b]Input filter time:[/b] Valid holding time can trigger the input for Digital Input 1-8 ports

[b]B.WiFi advanced config by hotspot without router: (Most time not need to use, you can skip this step)[/b]
1. Install WiFi antenna for Controller.
2. Make sure “DHCP” function is enabled by your router.
3. Enable your computer WiFi network.
4. Begin to config WiFi as follow steps:
Let your computer to connect WiFi wireless network name of “LPT230”

[Image: wifi-ap-1.jpg]
When wifi connected, open browser visit: http://10.10.100.254/

[Image: wifi-config-1.jpg]
[Image: wifi-config-2.jpg]
input the user name: admin password: admin
[Image: wifi-config-3.jpg]

now the default menu is Chinese , you can click “English” change to English language menu.
[Image: wifi-config-4.jpg]

this is English menu.
[Image: wifi-config-5.jpg]

Enter wifi work mode, default is “AP mode”
[Image: wifi-config-6.jpg]

Now we change to “STA mode”, “STA” means “Station”
[Image: wifi-config-7.jpg]

not need to “Restart” , just click “Back” button for other settings, at last you need Restart once.
[Image: wifi-config-8.jpg]

Press “Scan” to search your router’s wifi signal or you input manually.
[Image: wifi-config-9.jpg]
Chose your router’s wifi ssid
[Image: wifi-config-10.jpg]

there is a tip message for you to input password of your router.
[Image: wifi-config-11.jpg]

now input password of your router.
[Image: wifi-config-12.jpg]

also press “Back” begin for other settings.
[b]Note:[/b]
If you want to reset wifi for new config, you can use WiFi Reset button for re-config.
[b]B.Set Work Mode for remote control (Need internet and KinCony’s cloud server)[/b]
[Image: wifi-config-13.jpg]
now you want to use “KinCony smart home ” phone app for remote control, so make sure your Protocol line is “UDP” and Server address is “114.55.89.143”,Port is “5555”. now all setting is finished, we press “Save”, then restart.
[Image: wifi-config-14.jpg]

now you can restart power of your controller. Now you can use “KinCony Smart Home” app and PC software for remote control.
[b]C.Set Work Mode for local LAN control (without internet)[/b]
[Image: wifi-config-15.jpg]
Just change Protocol = TCP Server after “Save” Re-start power for controller. Now you can use “KBOX Smart” app and PC software for local control.
 
[b]3. How to use Phone APP and PC software in WAN/LAN[/b]
[b]Click below photo to see video:[/b]
A.APP- KinCony Smart Home (WAN:need internet)
[Image: kincony-smart-home.JPG]
B.APP- KBOX Smart (LAN:without internet)

[Image: kbox.png]
C.PC Software (LAN:without internet)

[Image: smart-controller-pc-software.jpg]
D.PC Software (WAN:need internet)

[Image: smart-controller-pc-software.jpg]

Print this item

  KC868-H32BS integrate to apple homekit by Node-Red
Posted by: admin - 04-14-2022, 06:29 AM - Forum: Development - No Replies


.pdf   KC868-H32 NODE RED HOMEKIT.pdf (Size: 3.3 MB / Downloads: 320)

Print this item

  KC868-G IR integration
Posted by: admin - 04-14-2022, 06:22 AM - Forum: KinCony integrate with Loxone home automation - No Replies


.pdf   KC868-G IR INTEGRATION.pdf (Size: 3.37 MB / Downloads: 376)

Print this item

  Automation using KC868-A16 and KC868-E16 diagram
Posted by: admin - 04-14-2022, 06:18 AM - Forum: KC868-A16 - No Replies


.pdf   Automation using KC868-A16 and KC868-E16.pdf (Size: 6.26 MB / Downloads: 566)

Print this item

  Lesson16 - integrate ZigBee device to home assistant by Zigbee2MQTT
Posted by: admin - 04-13-2022, 01:42 AM - Forum: Home automation training courses - Replies (5)


1. Add the repository URL under Supervisor->Add-on store->...->Manage add-on repositories:

https://github.com/zigbee2mqtt/hassio-zigbee2mqtt

2. Zigbee2mqtt add-on Configuration for home assistant

data_path: /config/zigbee2mqtt
external_converters: []
devices: devices.yaml
groups: groups.yaml
homeassistant: true
permit_join: false
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://192.168.1.96:1883
  user: mqtt
  password: '123'
serial:
  port: /dev/ttyACM0
advanced:
  log_level: info
  pan_id: 6754
  channel: 11
  network_key:
    - 1
    - 3
    - 5
    - 7
    - 9
    - 11
    - 13
    - 15
    - 0
    - 2
    - 4
    - 6
    - 8
    - 10
    - 12
    - 13
  availability_blocklist: []
  availability_passlist: []
device_options: {}
blocklist: []
passlist: []
queue: {}
frontend:
  port: 8099
experimental: {}
socat:
  enabled: false
  master: pty,raw,echo=0,link=/tmp/ttyZ2M,mode=777
  slave: tcp-listen:8485,keepalive,nodelay,reuseaddr,keepidle=1,keepintvl=1,keepcnt=5
  options: '-d -d'

3. feedback click action mqtt message:

  1: single
  2: double
  3: triple
  4: quadruple
  5: many

4. Xiaomi zigbee switch configure for home assistant by Zigbee2mqtt

sensor:
  - platform: mqtt
    name: Voltage
    state_topic: "zigbee2mqtt/0x00158d00067ec29e"
    value_template: "{{ value_json.battery }}"
    unit_of_measurement: "%"
    availability_topic: "zigbee2mqtt/bridge/state"
    payload_available: "online"
    payload_not_available: "offline"
    qos: 0
    device_class: battery

  - platform: mqtt
    name: signal
    state_topic: "zigbee2mqtt/0x00158d00067ec29e"
    value_template: "{{ value_json.linkquality }}"
    availability_topic: "zigbee2mqtt/bridge/state"
    payload_available: "online"
    payload_not_available: "offline"
    qos: 0
    device_class: signal_strength

  - platform: mqtt
    name: click
    state_topic: "zigbee2mqtt/0x00158d00067ec29e"
    value_template: "{{ value_json.click }}"
    availability_topic: "zigbee2mqtt/bridge/state"
    payload_available: "online"
    payload_not_available: "offline"

Note: ID need replace with your device. such as '0x00158d00067ec29e'

5. create a new automation:

Trigger type: State
Entity: sensor.click
To: single


Actions:
Action type: Call service
Service: Switch:Toggle
+ Pick entity

Print this item