How to use code fences

Tags: #<Tag:0x00007fe05e976198>

(Rich Koshak) #1

We all have to type this content over and over and over. Here is a posting we can all point to when the topic comes up.

Why use code fences?

Because rules, sitemap, logs, and configs are all but unreadable when code fences are not used.

When to use code fences?

Whenever one is posting any sort of code, config, log, and any text where line wrapping, indentation, and using an equal spaced font makes the text more legible.

How to use code fences?

Use 3 backticks (```)... Or use <code>... Get
code block
some code line 1
some code line 2
code block
some code line 1
some code line 2

If you are using a bit of code inline in a sentence use single backticks:
This is a sentence with `some code` in it.


This is a sentence with some code in it.

To use code fences for a block of code, first create the fences and then paste your code, logs, etc between the fences. To create the fences there are a number of icons at the top of the text entry box for writing a new topic or replying to a topic. Hover over the icon and it will tell you what the icon represents. Below is the icon, what the hover text says, and what it drops into your posting. If you just type in the “what it drops into posting” you do not need to use the icons.


    indent preformatted text by 4 spaces

This uses a monospaced font and preserves indentation and line wraps but dose not perform syntax highlighting.

openHAB *.items code fences

your items code goes here

openHAB *.rules code fences

your rules code goes here

openHAB *.sitemap code fences

your sitemap code goes here

JavaScript code fences

your javascript code goes here

generic code fences

your generic code goes here

If you are posting some other language that Discourse supports you can try to use that language in your code fences, it often will work.

python code goes here

Calculate periodic consumption of gas based on meter readings
Binding cant be configured in debug mode
TCP Binding - can't get it to work properly
How to send http request?
Horizon Media Box binding under OpenHab 2.0
Changing Vizio TV Inputs with Google Assistant via openHAB
[SOLVED] How to create a Timer to switch off a light?
Mysensors binding items error
[SOLVED] Installation on Windows 10
Ecolink PIR-ZWAVE2.5-ECO inclusion
Bticino My Home Server configuration
[SOLVED] Dimmer Rule with exec Binding
Linking COCO items through OpenHab2
Unable to pair with Zigbee Gateway
OpenWeatherMap Forecast not working
openHAB and local control
My Rollershutter is not working
openHAB2, 2.4, MAX! binding, command not send to hardware
Homematic radiator thermostat missing/loosing actuall temperature
How to ask a good question / Help Us Help You
FritzBoxTR064 binding: cannot check presence of device in network
[SOLVED] Calculating windchill
If value in Widget
[SOLVED] My Color Temperature Light does not work
[SOLVED] MQTT 2.x inbound command
Rule is not working
[SOLVED] Newbee: My mapping does not work
[SOLVED] OpenHAB 2.4 Binding homematic ON_TIME
GPSBinding Distance from location not working
No value in Item for Danfoss Popp Thermostat Zwave
Ecobee unable to set desired temperature
[SOLVED] What is the status on the Weather binding?
[Solved] MQTT2 setup on OH2
[SOLVED] Bticino Gateway Problem
Migrating MQTT1 items to MQTT2.4 items
Rules with TP-Link HS105 Smart Wi-Fi Plug
[SOLVED] Total timeout 1000 ms elapsed after Update to OH2.4
Pioneer Powerswitch not working
[SOLVED] Zwave Inverted RollerShutter
Hue Ambientlight Sensor
[SOLVED] New MQTT binding 2.4
Dome motion sensor ALARM_REPORT not processed successfully
Add Items to Homekit
[SOLVED] RRD4J error
[SOLVED] KNX Bindings offline when using text file
NodeMCU based MQTT multi-sensor with OLED display
X10, CM11a, ttyUSB0, Status: OFFLINE - COMMUNICATION_ERROR Serial port /dev/ttyUSB0 is in use by another application (Unknown Linux Application)
[SOLVED] Persistence with InfluxDB not storing data?
Help me - Turn off light after 5 minutes human body go off
Owntracks CloudMQTT Setup Help
[SOLVED] MQTT inbound items and MAP
Zigbee binding
Amazon Echo Control play Amazon Station
Kernel Panic
Rules are not performed after some uptime
Novelan Heatpump Binding doesn't reply useful values for state, extended_state and massflow
[SOLVED] KNX commands dont get send to the KNX BUS
Window shutter contact in Homekit?
Simulate, debug, test rules
New rule engine startup - rule initialisation
KNX Binding, Sitemap: Number Item is not send to bus
[SOLVED] REGEX not working for my after migration to openhab 2
Enigma2 sitemap
[Solved] [Google TTS] Chromecast Audio Sink not working
[SOLVED] Confused about HarmonyHub Sitemap and Items
[Solved] [Google TTS] Chromecast Audio Sink not working
Mysql Binding, Mysql Persistence - connection is not valid
Question about how createTimer works
[solved] [max] setting 'set_temp' does not do anything. i can read its value though
Controlling Thermostatic Valve with Android App
[Solved] MQTT - OpenHab2 communication issue
Z-Wave device association MCO Home
HTTP Binding for dimmers and status
Weather Binding UV Index not parsed (ForecastIO)
Trouble triggering off of dimmer
HTTP Binding for dimmers and status
[SOLVED] Create items from php json script
Going crazy with a rule, please help
[SOLVED] Problem with rules if
[MongoDB] Persistence Service cannot connect to MongoDB Atlas (DBaaS)
OH2.3 KNX - Can not write to the bus
[SOLVED] Gettings mismatch input "item" expecting "end" errors in rule
[SOLVED] OpenWebNet binding on OH2 - thermostat heating channel not updating
[Onkyo] Help with advanced troubleshooting
Zwave battery device status
My z-wave dongle acting weird not able to send commands to z-wave devices via OH2
[SOLVED] Parse file and make items
[SOLVED] OH2.3 Mqtt Tasmota setup issues
KNX does not work anymore with my items
KNX does not work anymore with my items
[SOLVED] Channel select with broadlink and mqtt
KNX rule does not work
How can I show in a string and trigger a switch if no no response received from http?
Problem writing data with OH2 + GRAFANA + INFLUXDB in WIN10
Help with timers and sleep in rules
Hue Bindung: identical Bulbs with different results / maybe binding to bridge communication issue
Requirements for myOpenhab Cloud connection
[SOLVED] Help understanding rules
[SOLVED] Help understanding rules
Knx in Homekit
restoreOnStartup doesn't transmit restored value to mqtt
Knx binding 2.3 configure KNX IP Gateway
Knx binding 2.3 configure KNX IP Gateway
[SOLVED] A simple rule for turning off power (=heating)
Windows PC remote control (Shutdown, …)
Configuration with Alexa Echo Dot
Help with turning lights on when garage door opens
[SOLVED] Help with a rule
Satel Binding 2.3.0
Reading Data from Solaredge inverters via Modbus TCP
[SOLVED] Rule Error "could not invoke method"
Homekit Color item status issue always on / Wifi LED Binding
Openhab2 2.1 MQTT Service initialization completed but not starting?
Sonoff TH16 is not sending Temp to openhab
Basics of a Lambda expression
Cron Job Rules not working
Cron Job Rules not working
Rule example: Engine heater based on temperature
Rule example: Engine heater based on temperature
OpenHab2 control Alexa Skill
Astro trigger fires rule more than once per day
Solaredge: problem with readout on sitemap
Trigger a puschbutton of a VMBGPOD (velbus)
[SOLVED] Xiaomi Humidity Sensor Read Values in Rules
Edimax Binding issue
Things with Battery do not react
Weather binding with OpenWeatherMap API
[SOLVED] Looking for help with MQTT and ESP8266 communication
Xiomi (MI) Switch rule - nothing happens
[SOLVED] Sitemap error
[SOLVED] Logview on ubuntu
Zibee Yale YRD216 PBDB
New z-wave device needed and existing device to be renamed
Rule for FOB
IR blaster
GPIO Contacts not updating
Screwed my OpenHab 2.2.0
Transformation throws exception
NOOB - Just stumbling in the Dark - Help with HHTP Switch or Energenie Mi|Home (UK)
executeCommandLine being executed but not responding
Update remote OLED with a mesage using MQTT
Wemo insight state toggling unexpectedly
Items failing to update
[SOLVED] Ultimate guide to debugging rules?
Generic Presence Detection
[SOLVED] Temperature and Humidity from Sonoff is not displaing in basicUI
[SOLVED] ESP8266 publishes four topics but not 5
Rules Not working after
Z-Wave-Bindung: Unsupported Thing - Fibaro CO needs database update
Rules to only fire when its :00 or :30
Strange error when updating an item file
Rule to disable rule - or alternative solution
Eurotronic Spirit Zwave Plus thermostats not being initialized
Simple Sync Rule please
Yale L1 Z-wave Unknown Device
The MUSH-MACHINE: Rule triggering on mqtt values, storing and displaying it
[SOLVED] Can't get my MQTT Binding to work (still connected but it does nothing)
Zwave with Razberry2 Unkown Device
Where to find syntax for createTimer command
IpCamera: New IP Camera Binding
[SOLVED] Minimote Unknown Device
[SOLVED] createTimer help to prevent rule triggering again and again for a period of time
Aeotec Smart Switch 6 change in Power level not triggering Rule
[SOLVED] RaspBee http get request processing
Basic UI / Sitemap printing command besided buttos
Show two separate strings from python script in sitemap
[SOLVED] OH 2.3 - Change in persistence handling for numbers?
[SOLVED] Room Automation using OpenHAB, KNXD and Raspberry Pi 3
[SOLVED] Issue with presence detection in Basic Ui
Design Pattern: Motion Sensor Timer
New User: Avalanche of Errors (Getting Smothered)
[SOLVED] Multiple sub-directories/nesting
Server ERROR 500 in Visual Studio Code
HUSBZB Zigbee setup
[SOLVED] Google Assistant responding to question about garage door
[SOLVED] Integrating openhab and google assistant
[SOLVED] Amazon dash button works with Hue for one set of hue lights, the other not so lucky
Help with rule for temp sensor
How to set up a controlled garage door?
[SOLVED} Arithmetic operations in rules
IHC failes in 2.3 release
KNX1 to KNX2 Migration Steps
Need help to setup MQTT Binding on OH2
Need help to setup MQTT Binding on OH2
Selection item doesn't work the first time
KNX bridge UID issue
Binary math in a openhab2 rule
Linking a string and integer together to create a string for notifications
[Solved] AVM Fritz DECT210 not detected
Modbus openHAB2 binding available for alpha testing
My first working automation - feedback on my rule
Zipato Color Channel- bulb does not respond
Items with multiple functions or states?
Installed GPIO Binding in OH2 and GPIO pins are not woring
[SOLVED] Problem adapting existing blinds to OpenHab
Can't initialize string variable
[SOLVED] Problem with fibaro motion sensor detection!
[SOLVED] "Failed to start The openHAB 2 Home Automation Bus Solution."
LifX Binding enters race condition of some sort. Causes LifX bulb(s) to flicker
1st time poster, another noob - with a functional design concept question
Openhab2 Nest binding - 2.2.0.SNAPSHOT An Updated 2.0 Binding that works!
Official Google Assistant Integration for openHAB
[SOLVED] Dump first text rule
[SOLVED] Mqtt state espurna
[SOLVED] Mqtt state espurna
How to turn ON/OFF Hue Lights with Xiaomi Switch?
POPP 9402 Smoke alarm triggers burglar item
How to setup a Sonoff 4ch in openHAB
Tradfri Binding: Slow reaction and communication error with gateway
Befehl wird nicht ausgeführt ( exec=">ON:)
[SOLVED] MQTT Help-cant read data to openhab
Http get?
Please Help XML Parsing with XPATH
SNMP binding not updating switch state in sitemap
Ecobee - Hold Temperature Not working for me
JSON Transformation Error
KNX Binding - I got lost
Samsung AC NewGen experience
Delay when setting items in OpenHAB
Help to create a rule "turn on a lamp when motion is detected but only after sunset until sunrise"
Absolute value of a decimal
OH2 on MacOS Sierra - Restarterrors
Need help with a rule
Aeotec Water Sensor 6 ZW122
Weird crap! with my HVAC and Openhab
[SOLVED] String item not updating from TCP binding
Milight Binding Switch White light
LCN binding and Alexa
[SOLVED] Rrdj4 configuration
Zwave Fibaro 212 not posting updates after upgrade
How do you add the hue motion sensor too OH (SOLVED)
[Solved] iCloud Presence Turn on outside light
Having Trouble configuring Items
Get local UV radiation -- prevent sunburn and skin cancer
Is it possible to force a LUX sensor to update?
Network issue with Novelan binding
[solved] InfluxDB persistence not connecting to database
[SOLVED] Problem with temperature
Missing BASIC Channel?
Configuration model 'test.rules' is either empty or cannot be parsed correctly!
No values from ds18b20 in Openhab2
Unknown device - I'm lost!
Rules - An error occurred during the script execution: null
Where is the www root please?
Use Array-Items and one Rule
Openhab2 rules problem. PaperUI rules present in Karaf scheduler, HABmin rules do not import or execute
Z-wave Exception during HTTP PUT request
[SOLVED] Sum up and multiply item values at startup
digitalSTROM openhab2 Devices won't work
Homematic CCU still initializing - again
My sitemap gets ignored - error in openhab.log
DMX Chaser Crashing out?
Need help with openhab2, KNX & exor ebis panel
HTTP POST binding - not working
Offline showing after registering into openHAB cloud
MySensors Serial Gateway not coming online in OH2
[SOLVED] Do I have to unplug my Z-Stick Gen 5 to include new devices?
RFSniffer, 433MHz receiver RPI and MQTT
NodeMCU MQTT LED Strip Controller Build & Config How-To Videos
Transformation JSONPATH doesn't work
How to configure a contact Item in a Sitemap
Schlage BE469 - Zwave binding with security - missing features
Creating a switch to turn rules on and off
Unifi camera integration
NullPointerException in ZWaveController latest build
Item state update delayed
playSound mit Squeezebox
Need help with tomorrows date
Zigbee Binding Unable to find Bulb
Check, whether sun is set in if statement in a rule
TCP Binding receive problem
Date format Rule doesn't working on OH2
Openhab 2 Lastest Motiondetector logger
Uninstalling Weather Binding uninstalls all others as well
Better way of doing this?
Using Java code in openhab2
OH2.2 suddenly logging stopped this morning
Timer - start when an switch turned on before executing the rule
Strange forum and stupid user (me)
New rule engine startup - rule initialisation
Issues with lists and service restart
[SOLVED] DHT22 not reading
(Scott Rushworth) #2

I always use the Preformatted Text </> icon. I’ll paste in code or a log, select it all, and then click the icon. But there is a trick for this and multi-line text… there needs to be a blank line between it and the previous text, or it won’t show up as fenced. So if your using the icon, and things aren’t displaying right in the preview window, put a blank line on top to separate it from the previous text.

(The Squid) #3

Another important feature of code wrapped in a code fence is the elimination of smart quotes. If you are copying and pasting code samples that our outside of a code fence you most likely will pick up smart quotes instead of the expected regular quotes causing errors within OpenHAB.

Code fences are your friends!!


(Rich Koshak) #4

The problem with pasting and then applying the code fences is that the forum will confer all of your quotes and double quotes to smart quotes which will not work in Rules.

Based on my experiments awhile back, code fences only if you lay down the fences before pasting in the code.

(Scott Rushworth) #5

Hmmm… this must be OS or browser specific. In looking back at some of my posts, none of the quotes were converted to smart quotes. And I’ve only ever done a paste, select, and </>. I’m using Win10 and Chrome.

(Vincent Regaud) #7

Hi Rich,

Maybe some screen shot with the icons would help others:
For example:


I would be happy to make the others, where should I post them?

String manipulation in rules
(Rich Koshak) #8

Good idea. I’ve made the original posting into a wiki. You can add the screenshots and makes any other changes now.

(Vincent Regaud) #9

Done, thank you

(Davide) #10

I found a bug! :bug:

On MacOS Mojave you can’t see:

*.rules code fences icon
*.sitemap code fences icon
JavaScript code fences icon
generic code fences icon

(Vincent Regaud) #11

Same on Ubuntu 2 latest Firefox updates

(Angelos) #12


(or this was done on purpose by the forum Admins not to confuse users and make it easier for them to use the *.items code fences? … it’s a mystery ! :smiley:)

Community/forum reply buttons
(Mark) #13

Hmm. I never even realized there were icons. LOL I always go old school and just manually type the beginning and ending ```

(Angelos) #14

Enclose your configs in:

This is my config

Note: Additional markdown for whoever is interested:

The above will become:

This is my config

[Solved] HABmin rule designer, can't get it to work
Helvar Router
[SOLVED] Does udp binding with regex have to be ((.*))?
(SiHui) #15

Maybe that custom plugin does not work anymore …

(Angelos) #16

If you check using F12 in Chrome (dev tools) you will see that some of the svg icons are missing… (I think) so the plugin may need some maintenance. good catch @sihui

We need @ThomDietrich back ! :smiley:

(Angelos) #17

updated first wiki post to show immediately how to use the generic code fences

edit: added the <code> html flavor also on the table that shows up on the first page