diff --git a/docs/README.md b/docs/README.md index b4437fe84..c68fe532e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,4 +12,5 @@ Do not add anything here, as it will overwritten with next rebuild. | [Channel Types](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/channelTypes.md) (35 total) | Channel types are often not required and don't have to be configured, but in some cases they are required for better device control from OpenBeken web panel. Channel types describes the kind of value stored in channel, for example, if you have a Tuya Fan Controller with 3 speeds control, you can set the channel type to LowMidHigh and it will display the correct UI radiobutton on OpenBeken panel.
Some channels have '_div10' or '_div100' sufixes. This is for TuyaMCU. This is needed because TuyaMCU sends values as integers, so it sends, for example, 215 for 21.5C temperature, and we store it internally as 215 and only convert to float for display. | | [FAQ](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/faq.md) (15 total) | Here is a detailed list of questions you may ask. Some information from docs is repeated here. | | [Console/Script commands](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md) (225 total) | There are multiple console commands that allow you to automate your devices. Commands can be entered manually in command line, can be send by HTTP (just like in Tasmota), can be send by MQTT and also can be scripted. | +| [Command Examples](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commandExamples.md) (6 total) | Here you can find some examples of console commands usage | | [Console/Script commands [Extended Edition]](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md) (225 total) | More details on commands. | diff --git a/docs/commandExamples.md b/docs/commandExamples.md new file mode 100644 index 000000000..0d3454e1f --- /dev/null +++ b/docs/commandExamples.md @@ -0,0 +1,34 @@ +# Console command examples +This file was autogenerated by running 'node scripts/getcommands.js' in the repository. +All questions/answers were taken from json file. + +This will send a Tasmota HTTP Toggle command every 15 seconds to given device. Repeats value here is '-1' because we want this event to stay forever. +```addRepeatingEvent 15 -1 SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle```
+ + + +This will send a Tasmota HTTP Toggle command to given device when a button on pin 8 is clicked (pin 8, NOT channel 8) +```addEventHandler OnClick 8 SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle```
+ + + +This will set a Tasmota HTTP Power0 ON command when a channel 1 value become non-zero +```addChangeHandler Channel1 != 0 SendGet http://192.168.0.112/cm?cmnd=Power0%20On```
+ + + +This will set a Tasmota HTTP Power0 OFF command when a channel 1 value become zero +```addChangeHandler Channel1 == 0 SendGet http://192.168.0.112/cm?cmnd=Power0%20Off```
+ + + +This will create a new repeating events with 1 repeat count and 60 seconds delay everytime Channel1 becomes 1. Basically, it will automatically turn off the light 60 seconds after you turn it on. TODO: clear previous event instance? +```addChangeHandler Channel1 == 1 addRepeatingEvent 60 1 setChannel 1 0```
+ + + +This simple timer will toggle LED state every 5 seconds. -1 hear means infinite repeats. The ! stands for negation and $led_enableAll is a constant that you can read to get 0 or 1. It works like $CH11, $CH4 etc (any number) for accessing channel value +```addRepeatingEvent 5 -1 led_enableAll !$led_enableAll```
+ + + diff --git a/docs/json/commandExamples.json b/docs/json/commandExamples.json new file mode 100644 index 000000000..a939b5b91 --- /dev/null +++ b/docs/json/commandExamples.json @@ -0,0 +1,26 @@ +[ +{ +"command": "addRepeatingEvent 15 -1 SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle", +"description": "This will send a Tasmota HTTP Toggle command every 15 seconds to given device. Repeats value here is '-1' because we want this event to stay forever." +}, +{ +"command": "addEventHandler OnClick 8 SendGet http://192.168.0.112/cm?cmnd=Power0%20Toggle", +"description": "This will send a Tasmota HTTP Toggle command to given device when a button on pin 8 is clicked (pin 8, NOT channel 8)" +}, +{ +"command": "addChangeHandler Channel1 != 0 SendGet http://192.168.0.112/cm?cmnd=Power0%20On", +"description": "This will set a Tasmota HTTP Power0 ON command when a channel 1 value become non-zero" +}, +{ +"command": "addChangeHandler Channel1 == 0 SendGet http://192.168.0.112/cm?cmnd=Power0%20Off", +"description": "This will set a Tasmota HTTP Power0 OFF command when a channel 1 value become zero" +}, +{ +"command": "addChangeHandler Channel1 == 1 addRepeatingEvent 60 1 setChannel 1 0", +"description": "This will create a new repeating events with 1 repeat count and 60 seconds delay everytime Channel1 becomes 1. Basically, it will automatically turn off the light 60 seconds after you turn it on. TODO: clear previous event instance?" +}, +{ +"command": "addRepeatingEvent 5 -1 led_enableAll !$led_enableAll", +"description": "This simple timer will toggle LED state every 5 seconds. -1 hear means infinite repeats. The ! stands for negation and $led_enableAll is a constant that you can read to get 0 or 1. It works like $CH11, $CH4 etc (any number) for accessing channel value" +} +] \ No newline at end of file diff --git a/docs/json/generic.json b/docs/json/generic.json index 6c7c92347..1b83ca507 100644 --- a/docs/json/generic.json +++ b/docs/json/generic.json @@ -5,5 +5,6 @@ "constants": "Every console command that takes an integer argument supports certain constant expansion. ", "flags": "Flags are global and allows you to alter behaviour of the device.", "drivers": "Drivers allows you to control certain peripherals or enable certain features that are off by default.", - "faq": "Here is a detailed list of questions you may ask. Some information from docs is repeated here." + "faq": "Here is a detailed list of questions you may ask. Some information from docs is repeated here.", + "commandExamples":"Here you can find some examples of console commands usage" } \ No newline at end of file diff --git a/scripts/getcommands.js b/scripts/getcommands.js index 814096fdb..4b5f4cec1 100644 --- a/scripts/getcommands.js +++ b/scripts/getcommands.js @@ -663,6 +663,7 @@ function readJSONFile(path) { let faq = readJSONFile("docs/json/faq.json"); let generic = readJSONFile("docs/json/generic.json"); +let commandExamples = readJSONFile("docs/json/commandExamples.json"); let faqmdshort = `# FAQ (Frequently Asked Questions) @@ -670,6 +671,12 @@ Here is the latest, up to date FAQ. This file was autogenerated by running 'node scripts/getcommands.js' in the repository. All questions/answers were taken from json file. +`; +let commandExamplesmdshort = + `# Console command examples +This file was autogenerated by running 'node scripts/getcommands.js' in the repository. +All questions/answers were taken from json file. + `; let channelsmdshort = @@ -796,6 +803,25 @@ for (let i = 0; i < faq.length; i++) { faqmdshort += '\n'; } +for (let i = 0; i < commandExamples.length; i++) { + + let ex = commandExamples[i]; + + commandExamplesmdshort += "" + ex.description; + commandExamplesmdshort += '\n'; + commandExamplesmdshort += "```" + ex.command + "```"; + commandExamplesmdshort += '
'; + commandExamplesmdshort += '\n'; + + commandExamplesmdshort += '\n'; + commandExamplesmdshort += '\n'; + commandExamplesmdshort += '\n'; +} + + + + + for (let i = 0; i < cnsts.length; i++) { @@ -906,6 +932,7 @@ writeDocMD('constants', constantsmdshort, cnsts, "Script constants", true, gener writeDocMD('channelTypes', channelsmdshort, channels, "Channel Types", true, generic.channels); writeDocMD('faq', faqmdshort, faq, "FAQ", false, generic.faq); writeDocMD('commands', mdshort, commands, "Console/Script commands", true, generic.commands); +writeDocMD('commandExamples', commandExamplesmdshort, commandExamples, "Command Examples", false, generic.commandExamples); writeDocMD('commands-extended', mdlong, commands, "Console/Script commands [Extended Edition]", false, "More details on commands.") let links_md =