Code: Select all
// Function node for Binary Sensors
// Declare variables
var number_plate = "ABC123";
// Binary Sensors which will give alert
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/doors_hood_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":204,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":204,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/doors_front_left_door_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":200,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":200,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/doors_front_right_door_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":203,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":203,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/doors_rear_left_door_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":201,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":201,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/doors_rear_right_door_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":202,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":202,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/doors_tailgate_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":205,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":205,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/windows_front_left_window_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":196,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":196,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/windows_front_right_window_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":199,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":199,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/windows_rear_left_window_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":197,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":197,"nvalue":4,"svalue":"Open"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/windows_rear_right_window_open/state"){
if (msg.payload == "close") {
msg.payload = {"command":"udevice","idx":198,"nvalue":1,"svalue":"Closed"};
} else {
msg.payload = {"command":"udevice","idx":198,"nvalue":4,"svalue":"Open"};
}
return msg;
}
// Binary Sensors which will give text
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/tyre_pressure_front_left_tyre_pressure/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":206,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":206,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/tyre_pressure_front_right_tyre_pressure/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":207,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":207,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/tyre_pressure_rear_left_tyre_pressure/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":208,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":208,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/tyre_pressure_rear_right_tyre_pressure/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":209,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":209,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/washer_fluid_level/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":218,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":218,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/brake_fluid/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":217,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":217,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/service_warning_status/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":224,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":224,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/bulb_failures/state"){
if (msg.payload == "safe") {
msg.payload = {"command":"udevice","idx":226,"nvalue":0,"svalue":"Safe"};
} else {
msg.payload = {"command":"udevice","idx":226,"nvalue":0,"svalue":"Unsafe"};
}
return msg;
}
// Binary Sensors not in use
//if (msg.topic == "volvo/" + number_plate + "/binary_sensor/any_door_open/state"){
//if (msg.payload == "close") {
//msg.payload = {"command":"udevice","idx":xxx,"nvalue":1,"svalue":"Closed"};
//} else {
//msg.payload = {"command":"udevice","idx":xxx,"nvalue":4,"svalue":"Open"};
//}
//return msg;
//}
//if (msg.topic == "volvo/" + number_plate + "/binary_sensor/any_window_open/state"){
//if (msg.payload == "close") {
//msg.payload = {"command":"udevice","idx":yyy,"nvalue":1,"svalue":"Closed"};
//} else {
//msg.payload = {"command":"udevice","idx":yyy,"nvalue":4,"svalue":"Open"};
//}
//return msg;
//}
if (msg.topic == "volvo/" + number_plate + "/binary_sensor/is_engine_running/state"){
if (msg.payload == "off") {
msg.payload = {"command":"udevice","idx":230,"nvalue":0,"svalue":"Off"};
} else {
msg.payload = {"command":"udevice","idx":230,"nvalue":0,"svalue":"On"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/lock/lock/state"){
if (msg.payload == "lock") {
msg.payload = {"command":"udevice","idx":228,"nvalue":0,"svalue":"Locked"};
} else {
msg.payload = {"command":"udevice","idx":228,"nvalue":0,"svalue":"Unlocked"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/switch/heater/state"){
if (msg.payload == "off") {
msg.payload = {"command":"udevice","idx":229,"nvalue":0,"svalue":"Off"};
} else {
msg.payload = {"command":"udevice","idx":229,"nvalue":0,"svalue":"On"};
}
return msg;
}
if (msg.topic == "volvo/" + number_plate + "/sensor/trips/state"){
msg.payload = {"command":"udevice","idx":227,"nvalue":0,"svalue":(msg.payload)};
return msg;
}
Perhaps, you can use it, but you have to replace the idx's for your idx's.
And change ABC123 with your number plate.