Piezo Node is not visible in HASS latest Version



  • Hi there,

    i have problems to get my piezo node working, it's my first "active node" which should get triggered on special events like intruder detected "arm_home"

    I used the Example Sketch "Alarm" i changed as well already the V_Status to V_Triggered as i saw it is deprecated in HASS.

    Mysensor version is still 1.6.

    Thanks for help in advance.

    /**

    • MySensors RoomSensor with piezo alarm for audio feedback, like weather alarm when there's a huricane alarm.
    • The alarm is just a standard alarm in your Home Automation controller.
    • Version 1.0
    • Created 25-10-2015
    • release date 25-10-2015
    • Author by Theo
    • Parts used:
      • Arduino ProMini 3.3V
      • 3V Piezo buzzer (is actually surprisingly loud for such a tiny PIEZO), You can greatly improve on the volume by wrapping a paper tube around the piezo
        */

    /**

    • Include all needed libraries.
      */
      #include <MySensor.h> // The core of this Sketch. Enables communication from the radio to the MySensors gateway
      #include <SPI.h> // Needed by the MySensors Radio, it communicates with the Arduino by SPI

    /**

    • Define the child ID's of the supported sensors.
      */
      #define SIRENE_CHILD_ID 10 // The child ID of the sirene as presented to the Domotica Controller

    /**

    • Declare constants for the PIN's we use in this sketch.
      */
      #define PIEZO_PIN 13 // The arduino pin to which the piezo buzzer is attached

    /**

    • Declare other constants used by the sketch
      */
      #define PIEZO_ON_DURATION 600 // The period the piezo makes a sound when the alarm is on and snooze mode is off.
      #define PIEZO_OFF_DURATION 500 // The silent period when the alarm is on and snooze mode is off

    /**

    • Section for MySensors specific variables and declarations.
      /
      #define SN "A SP" // The name of the sketch as being presented to the MySensors gateway. B.t.w. current Domoticz version ignores it
      #define SV "1.0" // The version of the sketch as being presented to the MySensors gateway. B.t.w. current Domoticz version ignores it
      MySensor gw; // You'll need this object for communication from an to the Gateway. Contains all logic inl the Radio communication
      MyMessage sireneMsg( SIRENE_CHILD_ID, V_STATUS ); // trying to figure out what type type to use to make it known as a siren..???
      // Message for sending the alarm on/off state to the MySensors gateway
      /
      *
    • Declare variables used by the Sketch
      */
      boolean alarmOn = false; // alarm state indicator. False meaning off, true meaning we're in business.
      unsigned long nextPiezoEvent = 0; // The next timestamp the piezo sound has to be turned on or off. We'll use the arduino's internal clock for this
      boolean piezoOn = false; // indicator whether the sound is on or off during the alarm

    /**

    • Initialize everything we need before we can start the Sketch:
      • setup MySensors communication
      • present the child id's to the MySensors gateway
      • declare pin modes and initialize the debouncer
        */
        void setup() {
        #ifdef DEBUG // turn on the Serial monitor if #define DEBUG is uncommented in MyConfig.h (MySensors library)
        Serial.begin( 115200 ); // only debug to serial monitor during development
        #endif
        // setup a connection to the MySensor's gateway and request an ID if we do not have one yet.
        gw.begin(incomingMessage);
        gw.sendSketchInfo(SN, SV);
        #ifdef DEBUG // Print some debug info
        Serial.println( "Radio is connect right." );
        #endif

    // present the children to the gateway
    gw.present( SIRENE_CHILD_ID, S_LIGHT, "Sirene" ); // S_LIGHT is not correct
    gw.sendBatteryLevel( 100, false ); // Let the Domotica controller no that we're a 100% powered sensor.
    gw.request( SIRENE_CHILD_ID , V_STATUS ); // request current state. An alarm might be active.

    // setup the pin's used by this Sketch
    pinMode( PIEZO_PIN, OUTPUT);
    }

    /**

    • Piezo event has been triggered, depending on the current sirence state we need to make some nois or turn it off.
    • We'll determine the timestamp of the next piezo event as well
      */
      void handlePiezoEvent() {
      unsigned long curMS = millis();
      if ( piezoOn == true ) { // Piezo is currently on, we need to switch it of
      digitalWrite( PIEZO_PIN, 0 );
      nextPiezoEvent = curMS + PIEZO_OFF_DURATION;
      piezoOn = false;
      }
      else { // Piezo is off, time to make some noise 😉
      analogWrite( PIEZO_PIN, 255 );
      nextPiezoEvent = curMS + PIEZO_ON_DURATION;
      piezoOn = true;
      }
      }

    /**

    • Main loop of the sketch.
      */
      void loop() {
      if ( alarmOn == true ) { // Alarm handling code
      if ( millis() >= nextPiezoEvent ) { // check if the piezo has to be turned on or off.
      handlePiezoEvent();
      }
      }
      gw.wait( 5 ); // Just wait 50s not really necessary but give the arduino some rest. It's working really hard for us and we should be grateful for that.
      // besides it calls gw.process() which we need for incomming messages.
      }

    /**

    • Call back handler, for handling messages send by the MySensors gateway
      */
      void incomingMessage(const MyMessage &message) {
      if ( message.type == V_STATUS ) { // Check if the Gateway has reported an Alarm_type message (should be an V_ALARM as off the next Domoticz release.
      if ( message.sensor == SIRENE_CHILD_ID ) { // Is the message for our alarm child?
      alarmOn = message.getBool(); // get alarm value sent by Domotica controller
      #ifdef DEBUG // print some debug info
      Serial.println( "Sirene state changed to " + (String)alarmOn );
      #endif
      if ( alarmOn == false ) { // turn off the alarm as asked by the Domotica controller
      analogWrite( PIEZO_PIN, 0 ); // turn off the noise
      }
      else { // Schedule the next piezo event
      nextPiezoEvent = 0;
      piezoOn = false;
      }
      }
      }
      }

  • Plugin Developer

    Hi!

    Please edit your post and put the code within code block markdown, ie three backticks, newline, code, newline, three backticks. It's hard to read otherwise.

    Also, if you can capture a debug level log from home assistant after start, and post that, it would be great. Keep all mysensors related lines. See https://home-assistant.io/components/logger/ for how to set log level, using logger component.

    Eg add this to your config:

    logger:
      default: info
      logs:
        mysensors.mysensors: debug
        homeassistant.components.mysensors: debug
    

    Please also post your home assistant config for mysensors.



  • Sorry for the late reply, i was a bit absent.

    17-02-28 21:50:59 DEBUG (Thread-13) [homeassistant.components.mysensors] Update sensor_update: node 24
    17-02-28 21:50:59 INFO (Thread-13) [homeassistant.components.mysensors] No sketch_name: node 24
    17-02-28 21:50:59 INFO (Thread-13) [homeassistant.components.mysensors] No sketch_name: node 24
    17-02-28 21:50:59 INFO (Thread-13) [homeassistant.components.mysensors] No sketch_name: node 24
    17-02-28 21:50:59 INFO (Thread-13) [homeassistant.components.mysensors] No sketch_name: node 24
    17-02-28 21:50:59 INFO (Thread-13) [homeassistant.components.mysensors] No sketch_name: node 24
    17-02-28 21:50:59 INFO (Thread-13) [homeassistant.components.mysensors] No sketch_name: node 24
    17-02-28 21:50:59 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 24-24-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    17-02-28 21:50:59 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:send: 0-0-24-24 s=255,c=3,t=6,pt=0,l=1,sg=0,st=ok:M
    17-02-28 21:51:01 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 24-24-0 s=255,c=3,t=11,pt=0,l=4,sg=0:A SP
    17-02-28 21:51:01 DEBUG (Thread-13) [homeassistant.components.mysensors] Update sensor_update: node 24
    17-02-28 21:51:01 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 24-24-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.0
    17-02-28 21:51:01 DEBUG (Thread-13) [homeassistant.components.mysensors] Update sensor_update: node 24
    17-02-28 21:51:01 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 24-24-0 s=10,c=0,t=3,pt=0,l=0,sg=0:
    17-02-28 21:51:01 DEBUG (Thread-13) [homeassistant.components.mysensors] Update sensor_update: node 24
    17-02-28 21:51:01 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 24-24-0 s=255,c=3,t=0,pt=1,l=1,sg=0:100
    17-02-28 21:51:01 DEBUG (Thread-13) [homeassistant.components.mysensors] Update sensor_update: node 24
    17-02-28 21:51:01 DEBUG (Thread-13) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 24-24-0 s=10,c=2,t=2,pt=0,l=0,sg=0:
    
    I miss the add entity line, like for the other sensor nodes:
    
     Adding new devices: <Entity S SP 6 1: None>
    
    

    Config as usual:

    gateways:

    • device: '/dev/ttyUSB0'
      persistence_file: '/root/.homeassistant/mysensors/mysensors.json'
      baud_rate: 115200
      debug: true
      persistence: true
      version: '1.5'
      #optimistic: 'true'

    Gateway sketch should be 1.6, i want to update soon to 2.1 but as i have plenty of nodes and no OTA intentionally running it will take a while and especially because of a lack of time.

    Thats the node sketch:

    /**
     * MySensors RoomSensor with piezo alarm for audio feedback, like weather alarm when there's a huricane alarm.
     * The alarm is just a standard alarm in your Home Automation controller. 
     *
     * Version      1.0
     * Created      25-10-2015
     * release date 25-10-2015
     * Author       by Theo
     *
     *
     * Parts used:
     * - Arduino ProMini 3.3V
     * - 3V Piezo buzzer (is actually surprisingly loud for such a tiny PIEZO), You can greatly improve on the volume by wrapping a paper tube around the piezo
     */
    
    /**
     * Include all needed libraries.
     */
    #include <MySensor.h>   // The core of this Sketch. Enables communication from the radio to the MySensors gateway
    #include <SPI.h>        // Needed by the MySensors Radio, it communicates with the Arduino by SPI
    
    /**
      * Define the child ID's of the supported sensors.
      */
    #define SIRENE_CHILD_ID 10 // The child ID of the sirene as presented to the Domotica Controller
    
    /**
      * Declare constants for the PIN's we use in this sketch.
      */
    #define PIEZO_PIN 8       // The arduino pin to which the piezo buzzer is attached
    
    /**
     * Declare other constants used by the sketch
     */
    #define PIEZO_ON_DURATION  600    // The period the piezo makes a sound when the alarm is on and snooze mode is off.
    #define PIEZO_OFF_DURATION 500    // The silent period when the alarm is on and snooze mode is off
    
    
    /**
      * Section for MySensors specific variables and declarations.
      */
    #define SN "A SP"  // The name of the sketch as being presented to the MySensors gateway. B.t.w. current Domoticz version ignores it
    #define SV "1.0"     // The version of the sketch as being presented to the MySensors gateway. B.t.w. current Domoticz version ignores it
    MySensor gw;         // You'll need this object for communication from an to the Gateway. Contains all logic inl the Radio communication
    MyMessage sireneMsg( SIRENE_CHILD_ID, V_STATUS ); // trying to figure out what type type to use to make it known as a siren..???
                                                     // Message for sending the alarm on/off state to the MySensors gateway
    /**
     * Declare variables used by the Sketch
     */
    boolean alarmOn = false;             // alarm state indicator. False meaning off, true meaning we're in business.
    unsigned long nextPiezoEvent = 0;    // The next timestamp the piezo sound has to be turned on or off. We'll use the arduino's internal clock for this
    boolean piezoOn = false;             // indicator whether the sound is on or off during the alarm
    
    /**
     * Initialize everything we need before we can start the Sketch:
     * - setup MySensors communication
     * - present the child id's to the MySensors gateway
     * - declare pin modes and initialize the debouncer
     */
    void setup() {
    #ifdef DEBUG // turn on the Serial monitor if #define DEBUG is uncommented in MyConfig.h (MySensors library)
      Serial.begin( 115200 ); // only debug to serial monitor during development
    #endif
      // setup a connection to the MySensor's gateway and request an ID if we do not have one yet.
      gw.begin(incomingMessage);
      gw.sendSketchInfo(SN, SV);
    #ifdef DEBUG // Print some debug info
      Serial.println( "Radio is connect right." );
    #endif
    
      // present the children to the gateway
      gw.present(SIRENE_CHILD_ID, S_LIGHT); // S_LIGHT is not correct
      gw.sendBatteryLevel(100); // Let the Domotica controller no that we're a 100% powered sensor.
      gw.request(SIRENE_CHILD_ID, V_STATUS); // request current state. An alarm might be active.
       
      // setup the pin's used by this Sketch
      pinMode( PIEZO_PIN, OUTPUT);
    }
    
    /**
     * Piezo event has been triggered, depending on the current sirence state we need to make some nois or turn it off.
     * We'll determine the timestamp of the next piezo event as well
     */
    void handlePiezoEvent() {
      unsigned long curMS = millis();
      if ( piezoOn == true ) { // Piezo is currently on, we need to switch it of
        digitalWrite( PIEZO_PIN, 0 );
        nextPiezoEvent = curMS + PIEZO_OFF_DURATION;
        piezoOn = false;
      }
      else { // Piezo is off, time to make some noise ;-)
        analogWrite( PIEZO_PIN, 255 );
        nextPiezoEvent = curMS + PIEZO_ON_DURATION;
        piezoOn = true;
      }
    }
    
    /** 
     * Main loop of the sketch.
     */
    void loop() {
      if ( alarmOn == true ) { // Alarm handling code
        if ( millis() >= nextPiezoEvent ) { // check if the piezo has to be turned on or off.
          handlePiezoEvent();
        }
      }
      gw.wait( 5 ); // Just wait 50s not really necessary but give the arduino some rest. It's working really hard for us and we should be grateful for that.
                    // besides it calls gw.process() which we need for incomming messages.
    }
    
    /**
     * Call back handler, for handling messages send by the MySensors gateway
     */
    void incomingMessage(const MyMessage &message) {
      if ( message.type == V_STATUS ) { // Check if the Gateway has reported an Alarm_type message (should be an V_ALARM as off the next Domoticz release.
        if ( message.sensor == SIRENE_CHILD_ID ) { // Is the message for our alarm child?
          alarmOn = message.getBool(); // get alarm value sent by Domotica controller
          #ifdef DEBUG // print some debug info
            Serial.println( "Sirene state changed to " + (String)alarmOn );
          #endif
          if ( alarmOn == false ) { // turn off the alarm as asked by the Domotica controller
            analogWrite( PIEZO_PIN, 0 ); // turn off the noise
          }
          else { // Schedule the next piezo event 
            nextPiezoEvent = 0;
            piezoOn = false;
          }
        }
      }
    }
    

    I changed already a couple Values in the sketch for and backward, but it didn't change anything.

    thank you for your help.


  • Plugin Developer

    You need to send at least one initial value of the sensor to home assistant, to have the sensor added to home assistant. Also feedback the new value to home assistant in the receive function when a state change occurs.



  • @martinhjelmare i'm rather new to active nodes, do you have an example or could you edit the code above?

    I just used reporting nodes till now, first try with my active one :-).

    Didn't find much examples for home-assistant with active nodes, basically it could be a switch sketch either i assume.



  • so smth like:

    void setup()
    {
    #ifdef DEBUG // turn on the Serial monitor if #define DEBUG is uncommented in MyConfig.h (MySensors library)
      Serial.begin( 115200 ); // only debug to serial monitor during development
    #endif
      // setup a connection to the MySensor's gateway and request an ID if we do not have one yet.
      gw.begin(incomingMessage);
      gw.sendSketchInfo(SN, SV);
    #ifdef DEBUG // Print some debug info
      Serial.println( "Radio is connect right." );
    #endif
      // Initialize the digital pin as an output.
      pinMode( PIEZO_PIN, OUTPUT);;
      gw.present(CHILD_ID, S_BINARY);
      gw.send(sireneMsg.set(0));
    }
    

    How does the feedback looks like in the receive part?



  • void incomingMessage(const MyMessage &message)
    {
      if (message.type == V_STATUS) {
         // Change sirene state.
         digitalWrite(PIEZO_PIN, message.getBool() ? 1 : 0);
         gw.send(sireneMsg.set(message.getBool() ? 1 : 0));
      }
    }
    

    That you mean with receive feedback right?


  • Plugin Developer

    Yes, like that, for both cases.



  • Thanks i will test it today in the evening.

    Btw thanks for your great implementation!

    i dont know if its in process but an IR receive via the dev panel would be awesome ;-).

    Can i shoot you a beer or smth? 😉 or smth from ali?


  • Plugin Developer

    No problem, glad to hear about user stories.

    Can you explain a bit more, what you mean with IR receive via dev panel? IR receive is a sensor type, right? It should be possible already to update any states in the states dev panel. Maybe I'm not following completely?

    Contributing in the form of feedback on what works and don't work is very appreciated. If you want to try Python, pull request for bug fixes or new features is also welcome. Thanks!


Log in to reply
 

Suggested Topics

  • 1
  • 3
  • 5
  • 2
  • 8

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts