Relay device not showing up in HA but does in .json



  • I have the following relay device that shows up in the .json file of HA, but will not appear on the dashboard as an available device. Guessing it doesn't like something about the sketch, but not sure what that might be.

    Sketch:

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     *
     * DESCRIPTION
     * Example sketch showing how to control physical relays.
     * This example will remember relay state after power failure.
     * http://www.mysensors.org/build/relay
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 100
    #include <MySensors.h>
    
    #define RELAY_PIN 2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    
    void before()
    {
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    void setup()
    {
    
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay", "1.0");
    
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
      }
    }
    
    
    void loop()
    {
    
    }
    
    void receive(const MyMessage &message)
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.getType()==V_STATUS) {
        // Change relay state
        digitalWrite(message.getSensor()-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
        // Store state in eeprom
        saveState(message.getSensor(), message.getBool());
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.getSensor());
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    .json file:

    {
        "0": {
            "sensor_id": 0,
            "children": {},
            "type": 18,
            "sketch_name": null,
            "sketch_version": null,
            "battery_level": 0,
            "protocol_version": "2.3.2",
            "heartbeat": 0
        },
        "100": {
            "sensor_id": 100,
            "children": {
                "1": {
                    "id": 1,
                    "type": 3,
                    "description": "",
                    "values": {}
                }
            },
            "type": 18,
            "sketch_name": "Relay",
            "sketch_version": "1.0",
            "battery_level": 0,
            "protocol_version": "2.3.2",
            "heartbeat": 0
        }
    


  • Hello, friend.
    Do you read this Presentation?



  • @cabat Thank you! Apparently, the MySensors sketch supplied in the Build section is not written to work with HA. I did take a stab at it and pop some code in the loop section, and the sensor now shows up but is not functional. I will have to dig more and determine what should be added to the sketch for it to work.

    Thanks much for the pointer.



  • @mrhutchinsonmn have you managed to get your node working under HA? I would migrate from Domoticz to HA, but I have never saw any working sketch 😄 (I use relay switch, some temp+hum, light level measure)



  • This post is deleted!


  • Please read carefully documentation for HA. https://www.home-assistant.io/integrations/mysensors/

    You need to send initial state of your sensors. There is example code for doing it. Basically you check in loop if the node just started and send some values to HA. After that your sensor will appear in HA.


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 3
  • 8
  • 1

55
Online

11.4k
Users

11.1k
Topics

112.7k
Posts