HI. I use this sketch to my lisght but in Home Assistant it show me it as SWITCH. Is any chance to change it in mysensors sketch to show in Home Assisnatnt as LIGHT ?
I have no idea, sorry...
Personally I use node red for automations, from there you can just address the node and child directly even when it isn't presented or not supported by home assistant.
I was so occupied checking everything related to MySensors that I completely forgot to check the home-assistant part.
I didn't specify the MySensors version in configuration.yaml, which defaults to 1.4 which doesn't support V_LEVEL...
Oh well, problem solved ^^
@martinhjelmare
Thanks martin. I think I got the code handled properly, but i'm getting a compile error.
/**
* 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-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/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 - Derrick Rockwell (@Drock1985)
*
* DESCRIPTION
*
*
*/
// Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#define MY_NODE_ID 21
#define MY_REPEATER_FEATURE //Enables Repeater feature for non-battery powered nodes.
#include <SPI.h>
#include <MySensors.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <BH1750.h>
#include <Wire.h>
unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
#define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
int lastTemperature = 0;
boolean receivedConfig = false;
boolean metric = true;
#define CHILD_ID_MOTION 1 // Id of the sensor child
#define CHILD_ID_TEMP 2 // ID of Temperature Sensor
#define CHILD_ID_LUX 3 // ID of Lux Sensor
BH1750 lightSensor;
// Initialize messages
MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msgLux(CHILD_ID_LUX, V_LEVEL); //Sets up custom units (this case LUX for Light)
MyMessage msgPrefix(CHILD_ID_LUX, V_UNIT_PREFIX); // Sends controller the LUX value instead of %
uint16_t lastlux = 0;
void setup()
{
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
lightSensor.begin();
// Startup up the OneWire library
sensors.begin();
// requestTemperatures() will not block current thread
sensors.setWaitForConversion(false);
send(msgPrefix.set("Lux"));
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("LuxMotionTempSensor", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_MOTION, S_MOTION);
present(CHILD_ID_TEMP, S_TEMP);
present(CHILD_ID_LUX, S_LIGHT_LEVEL);
}
void loop()
{
{
uint16_t lux = lightSensor.readLightLevel();// Get Lux value
Serial.println(lux);
if (lux != lastlux) {
send(msgLux.set(lux));
send(msgPrefix.set("Lux"));
lastlux = lux;
}}
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// Fetch and round temperature to one decimal
int temperature = (((sensors.getTempCByIndex(0)) * 10.)) / 10.;
#if COMPARE_TEMP == 1
if (lastTemperature != temperature && temperature != -127.00 && temperature != 85.00) {
#else
if (temperature != -127.00 && temperature != 85.00) {
#endif
// Send in the new temperature
send(msgTemp.set(temperature,1));
// Save new temperatures for next compare
lastTemperature = temperature;
}}
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
// Serial.println(tripped);
send(msgMotion(tripped?"1":"0")); // Send tripped value to gw
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
}
I'll try it again tomorrow.
Thank you again for pointing me in the right direction on custom units.
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.
I have encountered the same situation trying to use a switch to control some blinds.
Has there been any update on this issue from either Home Assistant or MySensors, or any workaround developed?