hlw8012arduino代码_Commands.md

## How to Use

Tasmota provides three powerful man machine interfaces for issuing commands: **MQTT**, **web** and **serial**

Every command **used without a parameter (payload) returns the current setting**.

* `Power` will return the status of Relay1

Instead of `0` you can use `off` or `false` and instead of `1` you can use `on` or `true`.

* `Power ON` turns Relay1 on

* `Power1 1` also turns Relay1 on

* `Power1 True` also turns Relay1 on

Replace `` in a command with the appropriate index number. Leave it empty to use the first available.

* `Power1` and `Power` both control Relay1

In commands with `x..y` value parameters use a number from `x` to `y` range.

When a command mentions resetting to *"firmware default"* it means the setting will revert to the one in the flashed binary file. If you used `user_config_override.h` at compile time it will revert to those.

> [!NOTE]

> Beside results initiated by a command (synchronous) you can get asynchronous results initiated by rule trigger, telemetry event, commands from other source or changed device values.

Simply put, other messages may precede messages published as a result of your commands.

> [!EXAMPLE] A `tele/%topic%/STATUS` message (sent every 300 seconds by default) may appear exactly after you issue `Power off` command and before you receive `stat/%topic%/RESULT = {"POWER":"OFF"}` message.

### ...with MQTT

To send commands and view responses you'll need an [MQTT client](http://www.hivemq.com/blog/seven-best-mqtt-client-tools).

Commands over MQTT are issued by using `cmnd/%topic%/` where `%topic%` is the topic of the device you're sending the command to. If there is no `` (an empty MQTT message/payload), a query is sent for current status of the ``.

See [MQTT](MQTT) article to find out more.

### ...with Web Requests

Commands can be executed via web (HTTP) requests, for example:

```

http:///cm?cmnd=Power%20TOGGLE

http:///cm?cmnd=Power%20On

http:///cm?cmnd=Power%20off

http:///cm?user=admin&password=joker&cmnd=Power%20Toggle

```

> [!NOTE] Any spaces or special characters must be replaced with their [ASCII hex codes](https://www.rapidtables.com/code/text/ascii-table.html). You must precede each hex code with `%`.

Most used ones are: `space` = `%20`   `;` = `%3B`

If you have set a password for web user interface access, this must be included (in plaintext) in the URL of the HTTP request, like so:

```

http:///cm?&user=&password=&cmnd=Power%20On

```

### ...in Console in the Web UI

**Console** menu in the web UI is a convenient place to send commands and it behaves similar to a terminal connection via serial bridge.

### ...over Serial Bridge

If you flashed the device via serial method you can connect to it with a terminal application (e.g. [Termite](https://www.compuphase.com/software_termite.htm) or Arduino IDE Serial Monitor) to issue commands and follow responses. This is a practical way to do a `Backlog` setup of your new device.

*The serial interface is set to 115200 bps except for devices that require a different baudrate.

### ...the Power of Backlog

`Backlog` command allows executing up to 30 consecutive commands with a single command line. Each command is separated by a semicolon (";"). `Backlog` is a useful feature to avoid numerous restarts when setting up a new device. You can use it to:

Set up both Wi-Fi AP's

```console

Backlog SSID1 ; Password1 ; SSID2 ; Password2

```

Configure MQTT broker address, MQTT credentials, device topic and activate a few custom options

```console

Backlog MqttHost ; MqttUser ; MqttPassword ; Topic ; SetOption53 1; PowerRetain on

```

For specific relay control, using backlog like a script

```console

Backlog Status 1; Power2 on; Delay 20; Power2 off; Status 4

```

When using [web](#web) requests *(You have to encode "space" as '%20' and ";" as '%3B')*

```http

http:///cm?user=admin&password=joker&cmnd=Backlog%20Power%20Toggle%3BPower1%20ff

```

#### Clear Backlog queue

A `Backlog` command without an argument clears an possible existing `Backlog` queue.

E.g. in case of command _`Backlog Power1 OFF; Delay 600; Power1 ON`_ the usage of an additional `Backlog` command without any argument within the delay time of 1 minute will delete the whole queue _`Power1 OFF; Delay 600; Power1 ON`_. Therefore `Power1 ON` command will not be executed and the relay would remain off.

## Command List

> [!WARNING] If you're using Tasmota versions earlier than v7.1 some of the commands might not work. Note that availability of some features and their associated commands is dependent on the options selected during the firmware compilation. Please consult the [builds](Builds) table for a reference of which features are available for each firmware variant.

### Control

Command|Parameters

:---|:---

Backlog|List of commands to be executed in sequence separated by `;`
See [Using Backlog](#the-power-of-backlog) for examples.

BlinkCount|Number of relay toggles ([blinks](#power)) **(does not control the status LED)**
`0` = blink many times before restoring power state
`1..32000` = set number of blinks *(default = `10`)*

BlinkTime|`2..3600` set duration, in 0.1 second increments, to [blink](#power) (i.e., toggle Power) for a relay **(does not control the status LED)**

ButtonDebounce|User control over button debounce timing
`40..1000` = set button debounce time in milliseconds *(default = `50`)*

Buzzer|`0` = stop active buzzer cycle
`,,,` = [read more...](peripherals/Buzzer)
`2,3` - Beep twice with 300 milliseconds duration and 100 milliseconds pause
`2,3,4` - Beep twice with 300 milliseconds duration and 400 milliseconds pause
`1,2,3,0xF54` (0000 0000 0000 0000 0000 1111 0101 0100). Each `1` bit beeps for 200 milliseconds and each bounded `0` bit pauses for 300 milliseconds

DevGroupShare|Set incoming and outgoing shared item mask.
`,` (default = 0xFFFFFFFF,0xFFFFFFFF)
1 = Power, 2 = Light brightness, 4 = Light fade/speed, 8 = Light scheme, 16 = Light color, 32 = Minimum brightness

FanSpeed|Fan speed control *(iFan02/iFan03 only)*
`0` = turn fan OFF
`1..3` = set fan speed
`+` = increase fan speed
`-` = decrease fan speed

Interlock|Relay interlock mode and group selection.
`0` = disable relay interlock for all relays (i.e., each relay is self-locking) *(default)*
`1` = set interlock mode for selected relays
Add up to 8 relays in 1 to 4 interlock groups, each separated by a space. For example
`1,2 3,4` = Group Relay1 and Relay2 in group 1 and Relay3 and Relay4 in group 2 (_note the space between the two groups_)
`1,2,3` = group Relay1, Relay2 and Relay3 in a single interlock group
`1 3 2,4` = Relay1 is in group 1, Relay3 in group 2, Relay2 and Relay4 in group 3

LedMask|Set a [bitmask](https://en.wikipedia.org/wiki/Mask_(computing)#Masking_bits_to_1) specifiying which relays control the LED indicator. [Read more...](LedMask)
`` = [bitwise](https://whatis.techtarget.com/definition/bitwise) value representing each relay. Values may be entered as either hexadecimal or decimal values (e.g., 0xFFFF = 65535).
`0xFFFF` (= 1111 1111 1111 1111) All relays control the power LED _(default)_
*[LedState](#ledstate) must be enabled (i.e., `!= 0`) in order for `LedMask` to take effect.*

LedPower|LED power state as on or off
`0` = turn LED OFF and set `LedState 0`
`1` = turn LED ON and set `LedState 8`
`2` = toggle LED and set `LedState 0`
(Use `Backlog LedPower 0; SetOption31 1` to disable LED even when Wi-Fi or MQTT is not connected)

LedPower|LED power state control. **Enabled only when LedLink(i) is configured**
`0` = turn LED OFF and set `LedState 0`
`1` = turn LED ON and set `LedState 0`
`2` = toggle LED and set `LedState 0`

LedState|Manage LED state
`0` = disable use of LED as much as possible
`1` = show power state on LED (LED on when power on) *(default)* *(inverted for Sonoff Touch/T1)*
`2` = show MQTT subscriptions as a LED blink
`3` = show power state and MQTT subscriptions as a LED blink
`4` = show MQTT publications as a LED blink
`5` = show power state and MQTT publications as a LED blink
`6` = show all MQTT messages as a LED blink
`7` = show power state and MQTT messages as a LED blink
`8` = LED on when Wi-Fi and MQTT are connected.
_*Cannot* be issued directly and is only activated when `LedPower` is switched from `0` to `1` due to a software function_

Power0|Control the power state simultaneously for all relays on the device
`0` / `off` = turn OFF
`1` / `on` = turn ON
`2` / `toggle` = if relay is `ON` switch to `OFF` and vice versa

Power|Control the corresponding Relay (enumerated) power state and also restart PulseTime
`0` / `off` / `false` = turn OFF
`1` / `on` / `true` = turn ON
`2` / `toggle` = if relay is `ON` switch to `OFF` and vice versa
`3` / `blink` = toggle power for [BlinkCount](#blinkcount) times each [BlinkTime](#blinktime) duration (at the end of `blink`, relay power is returned to pre-blink state)
`4` / `blinkoff` = stop blink sequence and return relay power to pre-blink state

PowerOnState|Control relay state when the device is _**powered up**_. [More information](PowerOnState)
`0` / `OFF` = keep relay(s) OFF after power up
`1` / `ON` = turn relay(s) ON after power up
`2` / `TOGGLE` = toggle relay(s) from last saved state
`3` = switch relay(s) to their last saved state *(default)*
`4` = turn relay(s) ON and disable further relay control
`5` = after a `PulseTime` period turn relay(s) ON (acts as inverted [`PulseTime`](Commands#pulsetime) mode)

PulseTime|Display the amount of `PulseTime` remaining on the corresponding Relay (enumerated)
`` Set the duration to keep the corresponding Relay `ON` when `Power ON` command is issued. After this amount of time, the relay will be turned `OFF`.
`0` / `OFF` = disable use of PulseTime for the corresponding Relay
`1..111` = set PulseTime for the corresponding Relay in 0.1 second increments
`112..64900` = set PulseTime for the corresponding Relay, offset by 100, in 1 second increments. Add 100 to desired interval in seconds, e.g., `PulseTime 113` = 13 seconds and `PulseTime 460` = 6 minutes (i.e., 360 seconds)

SwitchDebounce|User control over switch debounce timing
`40..1000` = set switch debounce time in milliseconds *(default = `50`)*

SwitchMode|[Switch mode](Buttons-and-Switches#switchmode)
`0` = toggle *(default)*
`1` = follow (0 = off, 1 = on)
`2` = inverted follow (0 = on, 1 = off)
`3` = pushbutton (default 1, 0 = toggle)
`4` = inverted pushbutton (default 0, 1 = toggle)
`5` = pushbutton with hold (default 1, 0 = toggle, Hold = hold)
`6` = inverted pushbutton with hold (default 0, 1 = toggle, hold = hold)
`7` = pushbutton toggle (0 = toggle, 1 = toggle)

See also|[`SetOption1`](#setoption1) - Set button multipress mode
[`SetOption11`](#setoption11) - Swap pushbutton single and double press functionality
[`SetOption13`](#setoption13) - Allow immediate action on single button press
[`SetOption26`](#setoption26) - Use indexes even when only one relay is present
[`SetOption31`](#setoption31) - Disable Wi-Fi LED status blinking
[`SetOption32`](#setoption32) - Set hold interval before sending `HOLD` action
[`SetOption40`](#setoption40) - Stop detecting any input change on button GPIO
[`SetOption67`](#setoption67) - Enable/Disable Buzzer

### Management

Command|Parameters

:---|:---

Delay|`2..3600` = set delay between two backlog commands with 0.1 second increment

DeepSleepTime|Time to enter [deep sleep mode](DeepSleep)
`0` = disable deep sleep mode *(default)*
`10..86400` = set deep sleep mode time period in seconds

Emulation|`0` = disable emulation *(default)*
`1` = enable Belkin WeMo emulation for [Alexa](integrations/Alexa)
`2` = enable Hue Bridge emulation for [Alexa](integrations/Alexa)

FriendlyName|`1` = Reset friendly name to firmware default
`` = set friendly name (32 char limit)

Gpios|Show list of available [components](Components#components-list) by name and index
`255` / `All` Show list of all [components](Components#components-list) by name and index

Gpio|Show current [component](Components#components-list) assignments of the Module's configurable GPIO
`255` / `All` Show [component](Components#components-list) assignments for all the devices available GPIO

Gpio|_For built-in Modules only. This command does not work for devices configured with a Template._
`` = assign a [component](Components) to `Gpio`

I2Cscan|Scan I2C bus and show addresses for found devices

I2CDriver|Enable / Disable I2C sensor drivers. [Read more...](I2CDevices)

LogHost|`1` = reset [syslog](https://www.sigmdel.ca/michel/ha/rpi/syslog_en.html) host to firmware default (`SYS_LOG_HOST`)
`` = set syslog host (32 chars max)

LogPort|`1` = reset [syslog](https://www.sigmdel.ca/michel/ha/rpi/syslog_en.html) port to firmware default (`SYS_LOG_PORT`)
`2..32766` = set syslog port

Modules|Show available modules by name and index

Module|Displays active module by name and index
`` = switch to Module and restart
`0` = switch to defined [template](Templates) and restart

MqttLog|`0` = disable logging via MQTT *(default)*
`1` = show only error messages
`2` = show error and info messages
`3` = show error, info and debug messages
`4` = show error, info and more debug messsages

NtpServer|NTP server setup (x= `1..3`)
`0` = clear NtpServer settings
`1` = reset NtpServer settings to firmware defaults
`` = set NtpServer host or IP address (32 char limit)

OtaUrl|Display current OTA URL
`1` = Reset OtaUrl to firmware default
`url` = set address for OTA (100 char limit)

Pwm|`0..1023` = set PWM value for channel

PwmFrequency|`1` = reset PWM frequency to 880Hz
`100..4000` = set PWM frequency (100Hz to 4kHz)

PwmRange|`1` = reset maximum PWM range to 1023
`255..1023` = set maximum PWM range

Reset|`1` = reset device settings to firmware defaults and restart
`2` = erase flash, reset device settings to firmware defaults and restart
`3` = erase System Parameter Area in flash (Wi-Fi calibration and related data) and restart
`4` = reset device settings to firmware defaults but retain Wi-Fi credentials and restart
`5` = erase all flash and reset parameters to firmware defaults but keep Wi-Fi settings and restart
`6` = erase all flash and reset parameters to firmware defaults but keep Wi-Fi and MQTT settings and restart
*(Erase of flash can take a few seconds to complete and there is no output during the erase process on the serial or web console)*
`99` = reset device bootcount to zero

Restart|`1` = restart device with configuration saved to flash
`99` = force restart device without configuration save
_For debug and testing stack trace dumps only:_
`-1` = force an Exception (28) crash
`-2` = force a Soft WDT reset (after a freeze of 2 seconds)
`-3` = force an OS watchdog reset (after a freeze of 120 seconds, **caution!**)

SaveData|`0` = save parameter changes only manually, e.g. with `Restart 1`
`1` = save parameter changes every second *(default)*
`2..3600` = save parameter changes every x second

SerialLog|Disable hardware serial bridge and
`0` = disable serial logging
`1` = show only error messages
`2` = show error and info messages *(default)*
`3` = show error, info and debug messages
`4` = show error, info and more debug messages
`SerialLog` will be disabled automatically 10 minutes after the device reboots.

Sleep|`0` = turn sleep off
`1..250` = set sleep duration in milliseconds to enable [energy saving](Energy-Saving) *(default = `50`)*

State|Display current device state and publish to `%prefix%/%topic%/RESULT` topic  »5.12.0

Status|` ` = show abbreviated [status information](JSON-Status-Responses#basic-response)
`0` = show all status information (1 - 11)
`1` = show device parameters information
`2` = show firmware information
`3` = show logging and telemetry information
`4` = show memory information
`5` = show network information
`6` = show MQTT information
`7` = show time information
`8` = show connected sensor information
`9` = show power thresholds *(only on modules with power monitoring)*
`10` = same as `Status 8` *(retained for backwards compatibility)*
`11` = show information equal to [`TelePeriod`](#teleperiod) state message
`12` = in case of crash to dump the call stack saved in RT memory

SysLog|`0` = disable syslog logging *(default)*
`1` = show only error messages
`2` = show error and info messages
`3` = show error, info and debug messages
`4` = show error, info and more debug messages

Template|Show current [Template](Templates)
`0` = create template from active module
`x` = create template from a [supported module](Modules)
`255` = merge current module and template settings into new template
`{ ... }` = store template in a [JSON payload](Templates#explanation-of-template-properties)
Does not activate the template. To activate use `Module 0`.

Time|`0` =

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值