logo elektroda
logo elektroda
X
logo elektroda

OpenBeken HTTP Channel Value Read: Ch<n>, GetChannel, JSON API, Firmware 1.17.x

User question

show channel value via http

Artificial Intelligence Response

Direct answer to the question

• For any OpenBeken device you can read the present value of a channel with a single HTTP GET request:
http://<device_ip>/cm?cmnd=Ch<idx> → returns the raw value as plain text.
• If you prefer a named command (added in recent builds) use:
http://<device_ip>/cm?cmnd=GetChannel <idx> → same result, but keeps the index in the reply.
• To obtain every channel at once (JSON) call:
http://<device_ip>/cm?cmnd=json or …cm?cmnd=getState.

Key points
– Replace <device_ip> with the actual IP of your module and <idx> with the numerical channel index (1-64).
– The request is idempotent, needs no body, works from any browser, curl, wget, Node-RED, etc.
– Returned type: plain integer/float for Ch<n>; structured JSON for json / getState.

Detailed problem analysis

  1. Channel concept
    • A “channel” in OpenBeken is a general-purpose variable that can hold a relay state, PWM level, sensor reading or any script value.
    • Indices start at 1; assignment is visible in the WebUI “Pins/Channels” page or with the CLI command channels.

  2. HTTP command interface
    • OpenBeken inherits the classic Tasmota-style /cm?cmnd=<command> endpoint.
    • The parser tokenises the remainder of the URI exactly as you would type it in the serial console.
    • Space between command and parameter must be URL-encoded (%20) unless you already separate parameters with +:
    …cm?cmnd=GetChannel%201 or …cm?cmnd=GetChannel+1.

  3. Command variants and typical replies
    Command
    Reply type Example reply
    Ch1 text 0 or 1 or 53.7
    GetChannel 1 text 1
    json JSON object {"1":1,"2":0,"8":75,"24":22.5}
    getState JSON see below
    AllChannels (build ≥1.17.x) CSV 1,0,75,22.5

    Example getState reply:

    {
    "DeviceName":"GarageDoor",
    "Uptime":"0T01:22:18",
    "WiFi_RSSI":-62,
    "Channels":{"1":0,"2":1,"8":75,"24":22.5}
    }
  4. Performance notes
    Ch<n> is fastest (few bytes).
    json is preferable when you need many values in one round-trip.
    • For real-time automation use MQTT or WebSockets; HTTP polling every second is acceptable for dashboards but not for millisecond-level control.

Current information and trends

– Firmware 1.17.x (February 2024) introduced the more explicit GetChannel, SetChannel, /api/channels and server-sent-events endpoint /events for streaming changes.
– A permissive CORS header can be enabled (addEventHandler http_pre_response cors_handler) so modern SPAs can fetch JSON directly from the device.
– Upcoming roadmap (community PR #615) will unify REST paths to /api/v1/channels/<idx> and add bearer-token auth.

Supporting explanations and details

Example curl usage:

# Read channel 2
curl -s "http://192.168.0.41/cm?cmnd=Ch2"
# Same with named command
curl -s "http://192.168.0.41/cm?cmnd=GetChannel%202"
# Read all as JSON and pretty-print with jq
curl -s "http://192.168.0.41/cm?cmnd=json" | jq .

Alias shortcut in autoexec.bat if you need human-readable webpage:

alias mydash "return <h1>Temp:$CH24&nbsp;°C Hum:$CH25&nbsp;%</h1>"
addEventHandler http_get "/status" mydash

Ethical and legal aspects

– If the endpoint is exposed outside your LAN, enable HTTP auth (setWebAuth admin strongPwd) or migrate to HTTPS reverse-proxy.
– Comply with GDPR/CCPA when publishing sensor data that could identify occupants (e.g., presence, energy use).

Practical guidelines

  1. Discover the IP quickly with mDNS (openbeken.local) or a network scanner.
  2. Test in browser first; then integrate into scripts or Home-Assistant’s REST sensor.
  3. For reliability keep polling interval ≥5 s to avoid DoS, or switch to MQTT.
  4. Firmware update may reset the web password—verify after flashing.

Possible disclaimers or additional notes

– Older images (<1.16) do not understand GetChannel; stick to Ch<n>.
– When a channel is not initialised the reply may be empty; initialise by SetChannel <idx> 0.

Suggestions for further research

• Examine the new /api/v1/ endpoints once merged.
• Benchmark SSE stream vs MQTT throughput for high-frequency sensor boards.
• Contribute to documentation at github.com/openshwprojects/OpenBK7231T_App_Doc.

Brief summary

A channel value can be queried over HTTP with one line:
http://<device_ip>/cm?cmnd=Ch<idx> (legacy) or …cm?cmnd=GetChannel <idx> (new).
For structured data use cm?cmnd=json.
Secure the web server, prefer MQTT for push updates, and keep firmware current to gain the richer REST API now under development.

Ask additional question

Wait...(2min)
Disclaimer: The responses provided by artificial intelligence (language model) may be inaccurate and misleading. Elektroda is not responsible for the accuracy, reliability, or completeness of the presented information. All responses should be verified by the user.