Coding items, sitemap, things etc help

Hey guys n gals,
im new here but have been running openhab for about a year now in its most basic form. I would very much like to learn to code and be able to understand how to write the items files and things etc but google isnt showing me much, so for the mean time i thought id try here to see if anyone would be kind enough to help me. im becoming overwhelmed and not sure where to go.

The setup and info regarding my setup:
I run openhab on windows 7, i use mosquitto to handle mqtt and run openhab 2.4.0
I use an arduino mega with a 16 channel relay board and ethernet breakout as a node.
so far i can control all 16 relays however they are all controlled only via the items file.
I have recently installed the “squeezebox binding” aswell as LMS (logitech media centre) and have added a squeezbox player (android) I have this working between web interface and android tablet just not in openhab.

What i need help with

  1. i want to understand how to code files such as items, things, rules etc

  2. im struggling to get the items, things and sitemaps to work with squeezebox, i have kind of had it work but then changed settings and lost it,

  3. id like to get to the stage i can understand how to do rules etc and be able to set routines and even get my amazon echo or google home to communicate and be able to control parts of my open hab system.

i have attached my items things and sitemap however my sitemap and things file may as well be empty as the code in them doesn’t appear to be working, i have also included the arduino mega sketch (cant remember who got it from credit to them) to show how it is communicating, any suggestions, help, changes etc greatly appreciated,

**Items**

String tablet_PlayFavorite "Play Favorite [%s]" { channel="squeezebox:squeezeboxplayer:myserver:801afa589fe7:playFavorite" }

Switch Light_PIN23 "Turn On Pin 23 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:23_0],>[mosquitto:arduino/lightControl:command:OFF:23_1],<[mosquitto:arduino/lightControl/23:state:default]", autoupdate="false" }
Switch Light_PIN24 "Turn On Pin 24 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:24_0],>[mosquitto:arduino/lightControl:command:OFF:24_1],<[mosquitto:arduino/lightControl/24:state:default]", autoupdate="false" }
Switch Light_PIN25 "Turn On Pin 25 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:25_0],>[mosquitto:arduino/lightControl:command:OFF:25_1],<[mosquitto:arduino/lightControl/25:state:default]", autoupdate="false" }
Switch Light_PIN26 "Turn On Pin 26 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:26_0],>[mosquitto:arduino/lightControl:command:OFF:26_1],<[mosquitto:arduino/lightControl/26:state:default]", autoupdate="false" }
Switch Light_PIN27 "Turn On Pin 27 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:27_0],>[mosquitto:arduino/lightControl:command:OFF:27_1],<[mosquitto:arduino/lightControl/27:state:default]", autoupdate="false" }
Switch Light_PIN28 "Turn On Pin 28 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:28_0],>[mosquitto:arduino/lightControl:command:OFF:28_1],<[mosquitto:arduino/lightControl/28:state:default]", autoupdate="false" }
Switch Light_PIN29 "Turn On Pin 29 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:29_0],>[mosquitto:arduino/lightControl:command:OFF:29_1],<[mosquitto:arduino/lightControl/29:state:default]", autoupdate="false" }
Switch Light_PIN30 "Turn On Pin 30 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:30_0],>[mosquitto:arduino/lightControl:command:OFF:30_1],<[mosquitto:arduino/lightControl/30:state:default]", autoupdate="false" }
Switch Light_PIN31 "Turn On Pin 31 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:31_0],>[mosquitto:arduino/lightControl:command:OFF:31_1],<[mosquitto:arduino/lightControl/31:state:default]", autoupdate="false" }
Switch Light_PIN32 "Turn On Pin 32 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:32_0],>[mosquitto:arduino/lightControl:command:OFF:32_1],<[mosquitto:arduino/lightControl/32:state:default]", autoupdate="false" }
Switch Light_PIN33 "Turn On Pin 33 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:33_0],>[mosquitto:arduino/lightControl:command:OFF:33_1],<[mosquitto:arduino/lightControl/33:state:default]", autoupdate="false" }
Switch Light_PIN34 "Turn On Pin 34 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:34_0],>[mosquitto:arduino/lightControl:command:OFF:34_1],<[mosquitto:arduino/lightControl/34:state:default]", autoupdate="false" }
Switch Light_PIN35 "Turn On Pin 35 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:35_0],>[mosquitto:arduino/lightControl:command:OFF:35_1],<[mosquitto:arduino/lightControl/35:state:default]", autoupdate="false" }
Switch Light_PIN36 "Turn On Pin 36 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:36_0],>[mosquitto:arduino/lightControl:command:OFF:36_1],<[mosquitto:arduino/lightControl/36:state:default]", autoupdate="false" }
Switch Light_PIN37 "Turn On Pin 37 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:37_0],>[mosquitto:arduino/lightControl:command:OFF:37_1],<[mosquitto:arduino/lightControl/37:state:default]", autoupdate="false" }
Switch Light_PIN38 "Turn On Pin 38 Relay" {mqtt=">[mosquitto:arduino/lightControl:command:ON:38_0],>[mosquitto:arduino/lightControl:command:OFF:38_1],<[mosquitto:arduino/lightControl/38:state:default]", autoupdate="false" }


**Sitemap**

Selection item=tablet_PlayFavorite label="Play Favorite"
**Things**

Bridge squeezebox:squeezeboxserver:myserver [ ipAddress="192.168.1.103", webport=9000, cliport=9090 ]
{
    Thing squeezeboxplayer tablet [ mac="80:1a:fa:58:9f:e7" ] //tablet
}
**Arduino Mega & ethernet & 16 relay**

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

#define MQTT_CLIENTID "lightSwitchArduino"
#define MQTT_SERVER "192.168.1.103"
#define MQTT_WILLTOPIC  "clients/LightSwitcharduino/"
#define MQTT_WILLMESSAGE  "dead"
#define TRUE    (1)

// Update these with values suitable for your network.
byte mac[]    = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x07 };
//byte server[] = { 192, 168, 1, 103 };
IPAddress ip(192, 168, 1, 50);
IPAddress server(192, 168, 1, 103);

const int StatLED = 13;

void callback(char* topic, byte* payload, unsigned int length);

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

void callback(char* topic, byte* payload, unsigned int length) 
{
  char buff[length + 1];
  int n;

  for (n = 0; n < length; n++) 
  {
    buff[n] = payload[n];
  }
  buff[n] = '\0';

  if (!strcmp(topic, "arduino/lightControl")) 
  {
   if(length==4) // only accepts message length of 4 (plus null): 1&2) two-digit-pin-number 3) underscore 4) one-digit-command-number
  {
    int number = buff[3] - '0'; // command number at byte 3 of message buffer, convert from ascii code for the number to integer
    int channel = (buff[0] - '0') * 10 ; // 10's digit of pin number at byte 0 of message buffer, convert from ascii character code to integer
    channel = channel + (buff[1] - '0') ; // add 1's digit of pin number from byte 1 of message buffer, convert from ascii to integer
      Serial.println(number);       
      Serial.println(channel);
      char feedbackTopic[256];  
      sprintf(feedbackTopic, "arduino/lightControl/%i",channel);
      pinMode(channel, OUTPUT);  // output
      digitalWrite(channel, number);

      if(number==0)
      {
        client.publish(feedbackTopic, "ON");
      }
      else
      {
        client.publish(feedbackTopic, "OFF");
      }
    }
  }
}

void setup() 
{
  Serial.begin(9600);
  pinMode(StatLED, OUTPUT);  // LED 
  pinMode(38, OUTPUT);
  digitalWrite(StatLED, LOW);
  digitalWrite(38, HIGH);
  
  char willtopic[128] = MQTT_WILLTOPIC;
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());
  
  if (client.connect(MQTT_CLIENTID, willtopic, MQTTQOS2, 1, MQTT_WILLMESSAGE))
  {
    //client.publish(willtopic, NULL, 0, TRUE);
    client.subscribe("arduino/lightControl");
    digitalWrite(StatLED, HIGH);
  }
}

void loop() 
{
  if(!client.connected())
  {
    char willtopic[128] = MQTT_WILLTOPIC;    
    client.connect(MQTT_CLIENTID, willtopic, MQTTQOS2, 1, MQTT_WILLMESSAGE);      
    //client.publish(willtopic, NULL, 0, TRUE);
    client.subscribe("arduino/lightControl");
    digitalWrite(StatLED, HIGH);
  }
  client.loop();  
}

How about reading the Documentation?
Especially in the MQTT Add-on Documentation you would see that you are using the wrong syntax in the items definition.

Are you using mqtt binding 2.x or 1.x? If using 2.x then as opus mentioned your item definitions are incorrect.

I recommend starting with one item and get it working. After the first item the others will be much easier. Then start out with a simple rule and advance from there.

Simple rule example using cron:

rule "Turn Couch Light On"

when

	Time cron "0 30 18 ? * *" // Turn light on at 6:30

then

	CouchLight.sendCommand(ON)

end

rule "Turn Couch Light Off"

when

	Time cron "0 30 23 ? * *" // Turn light off at 11:30

then 

	CouchLight.sendCommand(OFF)

end

Here’s a site to help with cron.
https://www.freeformatter.com/cron-expression-generator-quartz.html