diff --git a/NodeManager.cpp b/NodeManager.cpp
index 2481ded664be140cf5cae6d44f9748eb91c19e1f..604eb27b237bf623beaab5d036ce660b1905ba50 100644
--- a/NodeManager.cpp
+++ b/NodeManager.cpp
@@ -790,6 +790,9 @@ void SensorDigitalOutput::setInitialValue(int value) {
 void SensorDigitalOutput::setPulseWidth(int value) {
   _pulse_width = value;
 }
+void SensorDigitalOutput::setOnValue(int value) {
+  _on_value = value;
+}
 
 // main task
 void SensorDigitalOutput::onLoop() {
@@ -812,15 +815,21 @@ void SensorDigitalOutput::onReceive(const MyMessage & message) {
       Serial.print(F(" P="));
       Serial.println(_pulse_width);
     #endif
+    // reverse the value if needed
+    int value_to_write = value;
+    if (_on_value == LOW) {
+      if (value == HIGH) value_to_write = LOW;
+      if (value == LOW) value_to_write = HIGH;
+    }
     // set the value
-    digitalWrite(_pin, value);
-    _state = value;
+    digitalWrite(_pin, value_to_write);
     if (_pulse_width > 0) {
       // if this is a pulse output, restore the value to the original value after the pulse
       wait(_pulse_width);
-      digitalWrite(_pin, value == 0 ? HIGH: LOW);
+      digitalWrite(_pin, value_to_write == 0 ? HIGH: LOW);
     }
     // store the current value so it will be sent to the controller
+    _state = value;
     _value_int = value;
   }
   if (message.getCommand() == C_REQ) {
diff --git a/NodeManager.h b/NodeManager.h
index 040aa9f62b99b0e9b0a2433e00c20e80f7f96ee3..34241de76366bbd00008a288ba9ad80b397cc439 100644
--- a/NodeManager.h
+++ b/NodeManager.h
@@ -578,6 +578,8 @@ class SensorDigitalOutput: public Sensor {
     void setInitialValue(int value);
     // if greater than 0, send a pulse of the given duration in ms and then restore the output back to the original value (default: 0)
     void setPulseWidth(int value);
+    // define which value to set to the output when set to on (default: HIGH)
+    void setOnValue(int value);
     // define what to do at each stage of the sketch
     void onBefore();
     void onSetup();
@@ -585,6 +587,7 @@ class SensorDigitalOutput: public Sensor {
     void onReceive(const MyMessage & message);
   protected:
     int _initial_value = LOW;
+    int _on_value = HIGH;
     int _state = 0;
     int _pulse_width = 0;
 };
diff --git a/README.md b/README.md
index 159515a75c291a0f8eadf16f58f2a880b7565124..3f535e6237c00e94b96cc4a3c861b170474e3f80 100644
--- a/README.md
+++ b/README.md
@@ -442,6 +442,8 @@ Each sensor class can expose additional methods.
     void setInitialValue(int value);
     // if greater than 0, send a pulse of the given duration in ms and then restore the output back to the original value (default: 0)
     void setPulseWidth(int value);
+    // define which value to set to the output when set to on (default: HIGH)
+    void setOnValue(int value);
 ~~~
 
 #### SensorSwitch / SensorDoor / SensorMotion