@electrik
unfortunately it does not show up, there were some basic mistakes, stupid me
@BearWithBeard said in Missing sensor in home assistant integration:
I think what throws Home Assistant off is the mismatch of S and V types in the node sketch:
MyMessage msg(CHILD_ID, V_LEVEL); present(CHILD_ID, S_TEMP);
Since you're faking and trying to build a temperature sensor, you should use
V_TEMP
instead ofV_LEVEL
.
I also noticed that the sketch you posted above is very similar to the example on that page. I guess you just overlooked to adapt the V type accordingly.
Shame on me! That's it! I did miss this, embarrassing a bit. Thank you for pointing this out.
But there was one more very important config mistake I did!
In the integration configuration for serial gateway I gave mysensor version 2.3.2, which caused an error:
2021-05-02 12:37:58 DEBUG (MainThread) [homeassistant.components.mysensors.helpers] Discovering platform sensor with devIds: [('64693e37f3f094b5131163d2f441c016', 100, 1, 0)]
2021-05-02 12:37:58 DEBUG (MainThread) [mysensors.transport] Receiving 100;1;2;0;0;
2021-05-02 12:37:58 DEBUG (MainThread) [mysensors.transport] Sending 100;1;1;0;0;0.00
2021-05-02 12:37:58 INFO (MainThread) [homeassistant.components.mysensors] Adding new devices: [<Entity TestSensor 100 1: None>]
2021-05-02 12:37:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: TestSensor 100 1: value_type 0, value = 0.00
2021-05-02 12:37:58 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event device_registry_updated[L]: action=create, device_id=5fabcf2db00c71f24b515861d461605f>
2021-05-02 12:37:58 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform mysensors
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 427, in _async_add_entity
unit_of_measurement=entity.unit_of_measurement,
File "/usr/src/homeassistant/homeassistant/components/mysensors/sensor.py", line 118, in unit_of_measurement
float(self.gateway.protocol_version) >= 1.5
ValueError: could not convert string to float: '2.3.2'
2021-05-02 12:37:58 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 427, in _async_add_entity
unit_of_measurement=entity.unit_of_measurement,
File "/usr/src/homeassistant/homeassistant/components/mysensors/sensor.py", line 118, in unit_of_measurement
float(self.gateway.protocol_version) >= 1.5
ValueError: could not convert string to float: '2.3.2'
2021-05-02 12:37:58 DEBUG (MainThread) [mysensors.transport] Receiving 100;1;1;0;0;25.70
2021-05-02 12:37:58 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 100 child 1
The sensor was discovered but without any entity - something I already got in the past.
The correct mysensors gateway version for 2.3.2 is "only" 2.3:
By correcting these two things, my first "sensor" works as desired!
Many thanks for your quick support!
Don't worry I will be coming back
And for someone like me trying to test and looking for an example my corrected and working sketch:
/**
* Documentation: https://www.mysensors.org
* Support Forum: https://forum.mysensors.org
*
* https://www.mysensors.org/build/light
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <MySensors.h>
#define SN "TestSensor"
#define SV "1.0"
#define CHILD_ID 1
unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
MyMessage msg(CHILD_ID, V_TEMP);
bool initialValueSent = false;
void setup()
{
Serial.println("Starting Sensor");
delay(1000);
}
void presentation()
{
Serial.println("Presenting Sensor");
sendSketchInfo(SN, SV);
present(CHILD_ID, S_TEMP);
}
void loop()
{
if (!initialValueSent) {
Serial.println("Sending initial value");
send(msg.set(0.0,2));
Serial.println("Requesting initial value from controller");
request(CHILD_ID, V_TEMP);
wait(2000, C_SET, V_TEMP);
} else {
send(msg.set(25.0+random(0,30)/10.0,2));
sleep(SLEEP_TIME);
}
}
void receive(const MyMessage &message) {
if (message.type == V_TEMP) {
if (!initialValueSent) {
Serial.println("Receiving initial value from controller");
initialValueSent = true;
}
}
}
By the way I changed a bit the example from home assistance page. I did not like the way the first value from sketch is being sent. In the original code, even if the controller hasn't responded the sensor sends the values. I'm waiting with providing the sensor readings as long as the controller answers.
Cheers
Peter