Hi @martinhjelmare thanks for your reply, and appologies earlier as I was playing with a few config’s. My correct config for my configuration.yaml file is:
### MQTT ###
mqtt:
broker: 192.168.0.1
port: 1883
client_id: home-assistant
keepalive: 60
username: username
password: password
protocol: 3.1
### MySensors ###
mysensors:
gateways:
- device: mqtt
persistence_file: '/tmp/mysensors.json'
topic_in_prefix: 'P'
topic_out_prefix: 'S'
debug: true
optimistic: false
persistence: true
retain: true
version: 2.0
I have mosquitto running on the same box as HAS. I have an MQTT gateway at a separate address, that works great when connecting to it to either publish a relay change, watch a PIR being triggered from a remote sensor, etc. but for some odd reason the persistence file never get’s created ( I currently have it going to /tmp but never seems to be created, and I keep getting these errors in the log
16-10-02 20:48:17 mysensors.mysensors: File does not exist or is not readable: /tmp/mysensors.json
16-10-02 20:48:17 mysensors.mysensors: Trying backup file: /tmp/mysensors.json.bak
16-10-02 20:48:17 mysensors.mysensors: File does not exist or is not readable: /tmp/mysensors.json.bak
16-10-02 20:48:17 mysensors.mysensors: Failed to load sensors from file: /tmp/mysensors.json
I am assuming without a persistence file, HAS has an issue with the sensors / nodes. Is this correct?
FYI Also below is my gateway ino script, mostly from @Mihai ( thanks very much Mihai for a lot of great tips / configurations issues! )
// This MQTT gateway works on Arduino UNO
// Enable debug prints to serial monitor - does not fit the UNO board with actual defined sensors!
#define MY_DEBUG
// Enables and select radio type (if attached)
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#define MY_GATEWAY_MQTT_CLIENT
// Set this nodes subscripe and publish topic prefix
#define MY_MQTT_PUBLISH_TOPIC_PREFIX "P"
#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "S"
// Set MQTT client id
#define MY_MQTT_CLIENT_ID "0"
#define MY_GATEWAY_W5100
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
// W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
//#define MY_W5100_SPI_EN 4
// Enable Soft SPI for NRF radio (note different radio wiring is required)
// The W5100 ethernet module seems to have a hard time co-operate with
// radio on the same spi bus.
// The PINs mentioned here are for Arduino Mega2560 ! Color code is from MySensor site
#if !defined(MY_W5100_SPI_EN)
#define MY_SOFTSPI
#define MY_SOFT_SPI_SCK_PIN 14 // A0, Green
#define MY_SOFT_SPI_MISO_PIN 16 // A2, Violet
#define MY_SOFT_SPI_MOSI_PIN 15 // A1, Blue
#endif
// When W5100 is connected we have to move CE/CSN pins for NRF radio
#define MY_RF24_CE_PIN 5 // Orange
#define MY_RF24_CS_PIN 6 // Yellow
// Enable these if your MQTT broker requires usenrame/password
#define MY_MQTT_USER "username"
#define MY_MQTT_PASSWORD "password"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,0,X
// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,0,X
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// MQTT broker ip address.
#define MY_CONTROLLER_IP_ADDRESS 192,168,0,X
// The MQTT broker port to to open
#define MY_PORT 1883
/*
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
#define MY_INCLUSION_BUTTON_FEATURE
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
*/
#include <Ethernet.h>
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
// Set this offset if the sensor has a permanent small offset to the real temperatures
#define SENSOR_TEMP_OFFSET -1
/*
Ethernet use the following PINs, do not use them:
UNO: 4, 10, 11, 12, 13
*/
#define HUMIDITY_SENSOR_DIGITAL_PIN 3
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
DHT dht;
float lastTemp;
float lastHum;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
void setup()
{
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
metric = getConfig().isMetric;
}
void presentation()
{
// Send the sketch version information to the gateway
sendSketchInfo("TemperatureAndHumidityGateway", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_HUM, S_HUM);
present(CHILD_ID_TEMP, S_TEMP);
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
// Fetch temperatures from DHT sensor
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
} else if (temperature != lastTemp) {
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
send(msgTemp.set(temperature, 1));
#ifdef MY_DEBUG
Serial.print("T: ");
Serial.println(temperature);
#endif
}
// Fetch humidity from DHT sensor
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum) {
lastHum = humidity;
send(msgHum.set(humidity, 1));
#ifdef MY_DEBUG
Serial.print("H: ");
Serial.println(humidity);
#endif
}
sleep(SLEEP_TIME); //sleep a bit
}