diff --git a/sensors/src/ADCSensor.cpp b/sensors/src/ADCSensor.cpp
new file mode 100644
index 0000000..1ac0988
--- /dev/null
+++ b/sensors/src/ADCSensor.cpp
@@ -0,0 +1,312 @@
+/*
+// Copyright (c) 2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <unistd.h>
+
+#include <ADCSensor.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <iostream>
+#include <limits>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <string>
+
+static constexpr unsigned int SENSOR_POLL_MS = 500;
+static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+
+// scaling factor from hwmon
+static constexpr unsigned int SENSOR_SCALE_FACTOR = 1000;
+
+ADCSensor::ADCSensor(const std::string &path,
+                     sdbusplus::asio::object_server &objectServer,
+                     std::shared_ptr<sdbusplus::asio::connection> &conn,
+                     boost::asio::io_service &io,
+                     const std::string &sensor_name,
+                     std::vector<thresholds::Threshold> &&_thresholds,
+                     const double scale_factor,
+                     const std::string &sensorConfiguration) :
+    path(path),
+    objServer(objectServer), configuration(sensorConfiguration),
+    name(boost::replace_all_copy(sensor_name, " ", "_")),
+    thresholds(std::move(_thresholds)), scale_factor(scale_factor),
+    sensor_interface(objectServer.add_interface(
+        "/xyz/openbmc_project/sensors/voltage/" + name,
+        "xyz.openbmc_project.Sensor.Value")),
+    input_dev(io, open(path.c_str(), O_RDONLY)), wait_timer(io),
+    value(std::numeric_limits<double>::quiet_NaN()), err_count(0),
+    // todo, get these from config
+    max_value(20), min_value(0)
+{
+    if (thresholds::HasWarningInterface(thresholds))
+    {
+        threshold_interface_warning = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/voltage/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Warning");
+    }
+    if (thresholds::HasCriticalInterface(thresholds))
+    {
+        threshold_interface_critical = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/voltage/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Critical");
+    }
+    set_initial_properties(conn);
+    setup_read();
+}
+
+ADCSensor::~ADCSensor()
+{
+    // close the input dev to cancel async operations
+    input_dev.close();
+    wait_timer.cancel();
+    objServer.remove_interface(threshold_interface_warning);
+    objServer.remove_interface(threshold_interface_critical);
+    objServer.remove_interface(sensor_interface);
+}
+
+void ADCSensor::setup_read(void)
+{
+    boost::asio::async_read_until(
+        input_dev, read_buf, '\n',
+        [&](const boost::system::error_code &ec,
+            std::size_t /*bytes_transfered*/) { handle_response(ec); });
+}
+
+void ADCSensor::handle_response(const boost::system::error_code &err)
+{
+    if (err == boost::system::errc::bad_file_descriptor)
+    {
+        return; // we're being destroyed
+    }
+    std::istream response_stream(&read_buf);
+
+    if (!err)
+    {
+        std::string response;
+        std::getline(response_stream, response);
+
+        // todo read scaling factors from configuration
+        try
+        {
+            float nvalue = std::stof(response);
+
+            nvalue = (nvalue / SENSOR_SCALE_FACTOR) / scale_factor;
+
+            if (nvalue != value)
+            {
+                update_value(nvalue);
+            }
+            err_count = 0;
+        }
+        catch (std::invalid_argument)
+        {
+            err_count++;
+        }
+    }
+    else
+    {
+        std::cerr << "Failure to read sensor " << name << " at " << path
+                  << " ec:" << err << "\n";
+
+        err_count++;
+    }
+
+    // only send value update once
+    if (err_count == WARN_AFTER_ERROR_COUNT)
+    {
+        update_value(0);
+    }
+
+    response_stream.clear();
+    input_dev.close();
+    int fd = open(path.c_str(), O_RDONLY);
+    if (fd <= 0)
+    {
+        return; // we're no longer valid
+    }
+    input_dev.assign(fd);
+    wait_timer.expires_from_now(
+        boost::posix_time::milliseconds(SENSOR_POLL_MS));
+    wait_timer.async_wait([&](const boost::system::error_code &ec) {
+        if (ec == boost::asio::error::operation_aborted)
+        {
+            return; // we're being canceled
+        }
+        setup_read();
+    });
+}
+
+void ADCSensor::check_thresholds(void)
+{
+    if (thresholds.empty())
+        return;
+    for (auto threshold : thresholds)
+    {
+        if (threshold.direction == thresholds::Direction::HIGH)
+        {
+            if (value > threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+        else
+        {
+            if (value < threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+    }
+}
+
+void ADCSensor::update_value(const double &new_value)
+{
+    bool ret = sensor_interface->set_property("Value", new_value);
+    value = new_value;
+    check_thresholds();
+}
+
+void ADCSensor::assert_thresholds(thresholds::Level level,
+                                  thresholds::Direction direction, bool assert)
+{
+    std::string property;
+    std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
+    if (level == thresholds::Level::WARNING &&
+        direction == thresholds::Direction::HIGH)
+    {
+        property = "WarningAlarmHigh";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::WARNING &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "WarningAlarmLow";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::HIGH)
+    {
+        property = "CriticalAlarmHigh";
+        interface = threshold_interface_critical;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "CriticalAlarmLow";
+        interface = threshold_interface_critical;
+    }
+    else
+    {
+        std::cerr << "Unknown threshold, level " << level << "direction "
+                  << direction << "\n";
+        return;
+    }
+    if (!interface)
+    {
+        std::cout << "trying to set uninitialized interface\n";
+        return;
+    }
+    interface->set_property(property, assert);
+}
+
+void ADCSensor::set_initial_properties(
+    std::shared_ptr<sdbusplus::asio::connection> &conn)
+{
+    // todo, get max and min from configuration
+    sensor_interface->register_property("MaxValue", max_value);
+    sensor_interface->register_property("MinValue", min_value);
+    sensor_interface->register_property("Value", value);
+
+    for (auto &threshold : thresholds)
+    {
+        std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
+        std::string level;
+        std::string alarm;
+        if (threshold.level == thresholds::Level::CRITICAL)
+        {
+            iface = threshold_interface_critical;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "CriticalHigh";
+                alarm = "CriticalAlarmHigh";
+            }
+            else
+            {
+                level = "CriticalLow";
+                alarm = "CriticalAlarmLow";
+            }
+        }
+        else if (threshold.level == thresholds::Level::WARNING)
+        {
+            iface = threshold_interface_warning;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "WarningHigh";
+                alarm = "WarningAlarmHigh";
+            }
+            else
+            {
+                level = "WarningLow";
+                alarm = "WarningAlarmLow";
+            }
+        }
+        else
+        {
+            std::cerr << "Unknown threshold level" << threshold.level << "\n";
+            continue;
+        }
+        if (!iface)
+        {
+            std::cout << "trying to set uninitialized interface\n";
+            continue;
+        }
+        iface->register_property(
+            level, threshold.value,
+            [&](const double &request, double &oldValue) {
+                oldValue = request; // todo, just let the config do this?
+                threshold.value = request;
+                thresholds::persistThreshold(
+                    configuration, "xyz.openbmc_project.Configuration.ADC",
+                    threshold, conn);
+                return 1;
+            });
+        iface->register_property(alarm, false);
+    }
+    if (!sensor_interface->initialize())
+    {
+        std::cerr << "error initializing value interface\n";
+    }
+    if (threshold_interface_warning &&
+        !threshold_interface_warning->initialize())
+    {
+        std::cerr << "error initializing warning threshold interface\n";
+    }
+
+    if (threshold_interface_critical &&
+        !threshold_interface_critical->initialize())
+    {
+        std::cerr << "error initializing critical threshold interface\n";
+    }
+}
diff --git a/sensors/src/ADCSensorMain.cpp b/sensors/src/ADCSensorMain.cpp
new file mode 100644
index 0000000..640a729
--- /dev/null
+++ b/sensors/src/ADCSensorMain.cpp
@@ -0,0 +1,243 @@
+/*
+// Copyright (c) 2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <ADCSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_set.hpp>
+#include <experimental/filesystem>
+#include <fstream>
+#include <regex>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+static constexpr bool DEBUG = false;
+
+namespace fs = std::experimental::filesystem;
+static constexpr std::array<const char*, 1> SENSOR_TYPES = {
+    "xyz.openbmc_project.Configuration.ADC"};
+static std::regex INPUT_REGEX(R"(in(\d+)_input)");
+
+void createSensors(
+    boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+    boost::container::flat_map<std::string, std::unique_ptr<ADCSensor>>&
+        sensors,
+    std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+    const std::unique_ptr<boost::container::flat_set<std::string>>&
+        sensorsChanged)
+{
+    bool firstScan = sensorsChanged == nullptr;
+    // use new data the first time, then refresh
+    ManagedObjectType sensorConfigurations;
+    bool useCache = false;
+    for (const char* type : SENSOR_TYPES)
+    {
+        if (!getSensorConfiguration(type, dbusConnection, sensorConfigurations,
+                                    useCache))
+        {
+            std::cerr << "error communicating to entity manager\n";
+            return;
+        }
+        useCache = true;
+    }
+    std::vector<fs::path> paths;
+    if (!find_files(fs::path("/sys/class/hwmon"), R"(in\d+_input)", paths))
+    {
+        std::cerr << "No temperature sensors in system\n";
+        return;
+    }
+
+    // iterate through all found adc sensors, and try to match them with
+    // configuration
+    for (auto& path : paths)
+    {
+        std::smatch match;
+        std::string pathStr = path.string();
+
+        std::regex_search(pathStr, match, INPUT_REGEX);
+        std::string indexStr = *(match.begin() + 1);
+
+        auto directory = path.parent_path();
+        // convert to 0 based
+        size_t index = std::stoul(indexStr) - 1;
+        auto oem_name_path =
+            directory.string() + R"(/of_node/oemname)" + std::to_string(index);
+
+        if (DEBUG)
+            std::cout << "Checking path " << oem_name_path << "\n";
+        std::ifstream nameFile(oem_name_path);
+        if (!nameFile.good())
+        {
+            std::cerr << "Failure reading " << oem_name_path << "\n";
+            continue;
+        }
+        std::string oemName;
+        std::getline(nameFile, oemName);
+        nameFile.close();
+        if (!oemName.size())
+        {
+            // shouldn't have an empty name file
+            continue;
+        }
+        oemName.pop_back(); // remove trailing null
+
+        const SensorData* sensorData = nullptr;
+        const std::string* interfacePath = nullptr;
+        for (const std::pair<sdbusplus::message::object_path, SensorData>&
+                 sensor : sensorConfigurations)
+        {
+            if (!boost::ends_with(sensor.first.str, oemName))
+            {
+                continue;
+            }
+            sensorData = &(sensor.second);
+            interfacePath = &(sensor.first.str);
+            break;
+        }
+        if (sensorData == nullptr)
+        {
+            std::cerr << "failed to find match for " << oemName << "\n";
+            continue;
+        }
+        const std::pair<std::string, boost::container::flat_map<
+                                         std::string, BasicVariantType>>*
+            baseConfiguration = nullptr;
+        for (const char* type : SENSOR_TYPES)
+        {
+            auto sensorBase = sensorData->find(type);
+            if (sensorBase != sensorData->end())
+            {
+                baseConfiguration = &(*sensorBase);
+                break;
+            }
+        }
+
+        if (baseConfiguration == nullptr)
+        {
+            std::cerr << "error finding base configuration for" << oemName
+                      << "\n";
+            continue;
+        }
+
+        auto findSensorName = baseConfiguration->second.find("Name");
+        if (findSensorName == baseConfiguration->second.end())
+        {
+            std::cerr << "could not determine configuration name for "
+                      << oemName << "\n";
+            continue;
+        }
+        std::string sensorName =
+            sdbusplus::message::variant_ns::get<std::string>(
+                findSensorName->second);
+
+        // on rescans, only update sensors we were signaled by
+        auto findSensor = sensors.find(sensorName);
+        if (!firstScan && findSensor != sensors.end())
+        {
+            bool found = false;
+            for (auto it = sensorsChanged->begin(); it != sensorsChanged->end();
+                 it++)
+            {
+                if (boost::ends_with(*it, findSensor->second->name))
+                {
+                    sensorsChanged->erase(it);
+                    findSensor->second = nullptr;
+                    found = true;
+                    break;
+                }
+            }
+            if (!found)
+            {
+                continue;
+            }
+        }
+        std::vector<thresholds::Threshold> sensorThresholds;
+        if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds))
+        {
+            std::cerr << "error populating thresholds for " << sensorName
+                      << "\n";
+        }
+
+        auto findScaleFactor = baseConfiguration->second.find("scale_factor");
+        float scaleFactor = 1.0;
+        if (findScaleFactor != baseConfiguration->second.end())
+        {
+            scaleFactor = mapbox::util::apply_visitor(VariantToFloatVisitor(),
+                                                      findScaleFactor->second);
+        }
+        sensors[sensorName] = std::make_unique<ADCSensor>(
+            path.string(), objectServer, dbusConnection, io, sensorName,
+            std::move(sensorThresholds), scaleFactor, *interfacePath);
+    }
+}
+
+int main(int argc, char** argv)
+{
+    boost::asio::io_service io;
+    auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
+    systemBus->request_name("xyz.openbmc_project.ADCSensor");
+    sdbusplus::asio::object_server objectServer(systemBus);
+    boost::container::flat_map<std::string, std::unique_ptr<ADCSensor>> sensors;
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
+    std::unique_ptr<boost::container::flat_set<std::string>> sensorsChanged =
+        std::make_unique<boost::container::flat_set<std::string>>();
+
+    io.post([&]() {
+        createSensors(io, objectServer, sensors, systemBus, nullptr);
+    });
+
+    boost::asio::deadline_timer filterTimer(io);
+    std::function<void(sdbusplus::message::message&)> eventHandler =
+        [&](sdbusplus::message::message& message) {
+            if (message.is_method_error())
+            {
+                std::cerr << "callback method error\n";
+                return;
+            }
+            sensorsChanged->insert(message.get_path());
+            // this implicitly cancels the timer
+            filterTimer.expires_from_now(boost::posix_time::seconds(1));
+
+            filterTimer.async_wait([&](const boost::system::error_code& ec) {
+                if (ec == boost::asio::error::operation_aborted)
+                {
+                    /* we were canceled*/
+                    return;
+                }
+                else if (ec)
+                {
+                    std::cerr << "timer error\n";
+                    return;
+                }
+                createSensors(io, objectServer, sensors, systemBus,
+                              sensorsChanged);
+            });
+        };
+
+    for (const char* type : SENSOR_TYPES)
+    {
+        auto match = std::make_unique<sdbusplus::bus::match::match>(
+            static_cast<sdbusplus::bus::bus&>(*systemBus),
+            "type='signal',member='PropertiesChanged',path_namespace='" +
+                std::string(INVENTORY_PATH) + "',arg0namespace='" + type + "'",
+            eventHandler);
+        matches.emplace_back(std::move(match));
+    }
+
+    io.run();
+}
diff --git a/sensors/src/CPUSensor.cpp b/sensors/src/CPUSensor.cpp
new file mode 100644
index 0000000..66bca1f
--- /dev/null
+++ b/sensors/src/CPUSensor.cpp
@@ -0,0 +1,320 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <unistd.h>
+
+#include <CPUSensor.hpp>
+#include <Utils.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <iostream>
+#include <limits>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <string>
+
+static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+
+CPUSensor::CPUSensor(const std::string &path, const std::string &objectType,
+                     sdbusplus::asio::object_server &objectServer,
+                     std::shared_ptr<sdbusplus::asio::connection> &conn,
+                     boost::asio::io_service &io, const std::string &sensorName,
+                     std::vector<thresholds::Threshold> &&_thresholds,
+                     const std::string &sensorConfiguration) :
+    path(path),
+    objectType(objectType), objServer(objectServer),
+    name(boost::replace_all_copy(sensorName, " ", "_")), dbusConnection(conn),
+    thresholds(std::move(_thresholds)), configuration(sensorConfiguration),
+    sensor_interface(objectServer.add_interface(
+        "/xyz/openbmc_project/sensors/temperature/" + name,
+        "xyz.openbmc_project.Sensor.Value")),
+    input_dev(io, open(path.c_str(), O_RDONLY)), wait_timer(io),
+    value(std::numeric_limits<double>::quiet_NaN()), err_count(0),
+    // todo, get these from config
+    max_value(127), min_value(-128)
+{
+    if (thresholds::HasWarningInterface(thresholds))
+    {
+        threshold_interface_warning = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/temperature/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Warning");
+    }
+    if (thresholds::HasCriticalInterface(thresholds))
+    {
+        threshold_interface_critical = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/temperature/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Critical");
+    }
+    set_initial_properties(conn);
+    isPowerOn(dbusConnection); // first call initializes
+    setup_read();
+}
+
+CPUSensor::~CPUSensor()
+{
+    // close the input dev to cancel async operations
+    input_dev.close();
+    wait_timer.cancel();
+    objServer.remove_interface(threshold_interface_warning);
+    objServer.remove_interface(threshold_interface_critical);
+    objServer.remove_interface(sensor_interface);
+}
+
+void CPUSensor::setup_read(void)
+{
+    boost::asio::async_read_until(
+        input_dev, read_buf, '\n',
+        [&](const boost::system::error_code &ec,
+            std::size_t /*bytes_transfered*/) { handle_response(ec); });
+}
+
+void CPUSensor::handle_response(const boost::system::error_code &err)
+{
+    if (err == boost::system::errc::bad_file_descriptor)
+    {
+        return; // we're being destroyed
+    }
+    std::istream response_stream(&read_buf);
+    if (!err)
+    {
+        std::string response;
+        try
+        {
+            std::getline(response_stream, response);
+            float nvalue = std::stof(response);
+            response_stream.clear();
+            nvalue /= CPUSensor::SENSOR_SCALE_FACTOR;
+            if (nvalue != value)
+            {
+                update_value(nvalue);
+            }
+            err_count = 0;
+        }
+        catch (const std::invalid_argument &)
+        {
+            err_count++;
+        }
+    }
+    else
+    {
+        err_count++;
+    }
+
+    // only send value update once
+    if (err_count == WARN_AFTER_ERROR_COUNT)
+    {
+        // only an error if power is on
+        if (isPowerOn(dbusConnection))
+        {
+            std::cerr << "Failure to read sensor " << name << " at " << path
+                      << "\n";
+            update_value(0);
+            err_count++;
+        }
+        else
+        {
+            err_count = 0; // check power again in 10 cycles
+            sensor_interface->set_property(
+                "Value", std::numeric_limits<double>::quiet_NaN());
+        }
+    }
+
+    response_stream.clear();
+    input_dev.close();
+    int fd = open(path.c_str(), O_RDONLY);
+    if (fd <= 0)
+    {
+        return; // we're no longer valid
+    }
+    input_dev.assign(fd);
+    wait_timer.expires_from_now(
+        boost::posix_time::milliseconds(CPUSensor::SENSOR_POLL_MS));
+    wait_timer.async_wait([&](const boost::system::error_code &ec) {
+        if (ec == boost::asio::error::operation_aborted)
+        {
+            return; // we're being canceled
+        }
+        setup_read();
+    });
+}
+
+void CPUSensor::check_thresholds(void)
+{
+    if (thresholds.empty())
+        return;
+    for (auto threshold : thresholds)
+    {
+        if (threshold.direction == thresholds::Direction::HIGH)
+        {
+            if (value > threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+        else
+        {
+            if (value < threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+    }
+}
+
+void CPUSensor::update_value(const double &new_value)
+{
+    sensor_interface->set_property("Value", new_value);
+    value = new_value;
+    check_thresholds();
+}
+
+void CPUSensor::assert_thresholds(thresholds::Level level,
+                                  thresholds::Direction direction, bool assert)
+{
+    std::string property;
+    std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
+    if (level == thresholds::Level::WARNING &&
+        direction == thresholds::Direction::HIGH)
+    {
+        property = "WarningAlarmHigh";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::WARNING &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "WarningAlarmLow";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::HIGH)
+    {
+        property = "CriticalAlarmHigh";
+        interface = threshold_interface_critical;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "CriticalAlarmLow";
+        interface = threshold_interface_critical;
+    }
+    else
+    {
+        std::cerr << "Unknown threshold, level " << level << "direction "
+                  << direction << "\n";
+        return;
+    }
+    if (!interface)
+    {
+        std::cout << "trying to set uninitialized interface\n";
+        return;
+    }
+    interface->set_property(property, assert);
+}
+
+void CPUSensor::set_initial_properties(
+    std::shared_ptr<sdbusplus::asio::connection> &conn)
+{
+    // todo, get max and min from configuration
+    sensor_interface->register_property("MaxValue", max_value);
+    sensor_interface->register_property("MinValue", min_value);
+    sensor_interface->register_property("Value", value);
+
+    for (auto &threshold : thresholds)
+    {
+        std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
+        std::string level;
+        std::string alarm;
+        if (threshold.level == thresholds::Level::CRITICAL)
+        {
+            iface = threshold_interface_critical;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "CriticalHigh";
+                alarm = "CriticalAlarmHigh";
+            }
+            else
+            {
+                level = "CriticalLow";
+                alarm = "CriticalAlarmLow";
+            }
+        }
+        else if (threshold.level == thresholds::Level::WARNING)
+        {
+            iface = threshold_interface_warning;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "WarningHigh";
+                alarm = "WarningAlarmHigh";
+            }
+            else
+            {
+                level = "WarningLow";
+                alarm = "WarningAlarmLow";
+            }
+        }
+        else
+        {
+            std::cerr << "Unknown threshold level" << threshold.level << "\n";
+            continue;
+        }
+        if (!iface)
+        {
+            std::cout << "trying to set uninitialized interface\n";
+            continue;
+        }
+        if (threshold.writeable)
+        {
+            iface->register_property(
+                level, threshold.value,
+                [&](const double &request, double &oldValue) {
+                    oldValue = request; // todo, just let the config do this?
+                    threshold.value = request;
+                    thresholds::persistThreshold(configuration, objectType,
+                                                 threshold, conn);
+                    return 1;
+                });
+        }
+        else
+        {
+            iface->register_property(level, threshold.value);
+        }
+        iface->register_property(alarm, false);
+    }
+    if (!sensor_interface->initialize())
+    {
+        std::cerr << "error initializing value interface\n";
+    }
+    if (threshold_interface_warning &&
+        !threshold_interface_warning->initialize())
+    {
+        std::cerr << "error initializing warning threshold interface\n";
+    }
+
+    if (threshold_interface_critical &&
+        !threshold_interface_critical->initialize())
+    {
+        std::cerr << "error initializing critical threshold interface\n";
+    }
+}
diff --git a/sensors/src/CPUSensorMain.cpp b/sensors/src/CPUSensorMain.cpp
new file mode 100644
index 0000000..d6d68ad
--- /dev/null
+++ b/sensors/src/CPUSensorMain.cpp
@@ -0,0 +1,510 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <fcntl.h>
+#include <linux/peci-ioctl.h>
+
+#include <CPUSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_set.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/process/child.hpp>
+#include <experimental/filesystem>
+#include <fstream>
+#include <regex>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+static constexpr bool DEBUG = false;
+
+enum State
+{
+    OFF,  // host powered down
+    ON,   // host powered on
+    READY // host powered on and mem test passed - fully ready
+};
+
+struct CPUConfig
+{
+    CPUConfig(const int& address, const std::string& overlayName,
+              const State& st) :
+        addr(address),
+        ovName(overlayName), state(st)
+    {
+    }
+    int addr;
+    std::string ovName;
+    State state;
+
+    bool operator<(const CPUConfig& rhs) const
+    {
+        return (ovName < rhs.ovName);
+    }
+};
+
+static constexpr const char* DT_OVERLAY = "/usr/bin/dtoverlay";
+static constexpr const char* OVERLAY_DIR = "/tmp/overlays";
+static constexpr const char* PECI_DEV = "/dev/peci0";
+static constexpr const unsigned int RANK_NUM_MAX = 8;
+
+namespace fs = std::experimental::filesystem;
+static constexpr const char* CONFIG_PREFIX =
+    "xyz.openbmc_project.Configuration.";
+static constexpr std::array<const char*, 3> SENSOR_TYPES = {
+    "SkylakeCPU", "BroadwellCPU", "HaswellCPU"};
+
+const static std::regex ILLEGAL_NAME_REGEX("[^A-Za-z0-9_]");
+
+void createSensors(
+    boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+    boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>>&
+        sensors,
+    boost::container::flat_set<CPUConfig>& configs,
+    std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
+{
+    bool available = false;
+    for (CPUConfig cpu : configs)
+    {
+        if (cpu.state != State::OFF)
+        {
+            available = true;
+            break;
+        }
+    }
+    if (!available)
+    {
+        return;
+    }
+
+    // use new data the first time, then refresh
+    ManagedObjectType sensorConfigurations;
+    bool useCache = false;
+    for (const char* type : SENSOR_TYPES)
+    {
+        if (!getSensorConfiguration(CONFIG_PREFIX + std::string(type),
+                                    dbusConnection, sensorConfigurations,
+                                    useCache))
+        {
+            std::cerr << "error communicating to entity manager\n";
+            return;
+        }
+        useCache = true;
+    }
+
+    std::vector<fs::path> oemNamePaths;
+    if (!find_files(fs::path(R"(/sys/bus/peci/devices)"),
+                    R"(peci\d+/\d+-.+/of_node/oemname1$)", oemNamePaths, 2))
+    {
+        std::cerr << "No CPU sensors in system\n";
+        return;
+    }
+
+    for (fs::path& oemNamePath : oemNamePaths)
+    {
+        std::ifstream nameFile(oemNamePath);
+        if (!nameFile.good())
+        {
+            std::cerr << "Failure reading " << oemNamePath << "\n";
+            continue;
+        }
+        std::string oemName;
+        std::getline(nameFile, oemName);
+        nameFile.close();
+        if (!oemName.size())
+        {
+            // shouldn't have an empty name file
+            continue;
+        }
+        oemName.pop_back(); // remove trailing null
+        if (DEBUG)
+            std::cout << "Checking: " << oemNamePath << ": " << oemName << "\n";
+
+        const SensorData* sensorData = nullptr;
+        const std::string* interfacePath = nullptr;
+        for (const std::pair<sdbusplus::message::object_path, SensorData>&
+                 sensor : sensorConfigurations)
+        {
+            if (!boost::ends_with(sensor.first.str, oemName))
+            {
+                continue;
+            }
+            sensorData = &(sensor.second);
+            interfacePath = &(sensor.first.str);
+            break;
+        }
+        if (sensorData == nullptr)
+        {
+            std::cerr << "failed to find match for " << oemName << "\n";
+            continue;
+        }
+        const std::pair<std::string, boost::container::flat_map<
+                                         std::string, BasicVariantType>>*
+            baseConfiguration = nullptr;
+        std::string sensorObjectType;
+        for (const char* type : SENSOR_TYPES)
+        {
+            sensorObjectType = CONFIG_PREFIX + std::string(type);
+            auto sensorBase = sensorData->find(sensorObjectType);
+            if (sensorBase != sensorData->end())
+            {
+                baseConfiguration = &(*sensorBase);
+                break;
+            }
+        }
+
+        if (baseConfiguration == nullptr)
+        {
+            std::cerr << "error finding base configuration for" << oemName
+                      << "\n";
+            continue;
+        }
+
+        auto findCpuId = baseConfiguration->second.find("CpuID");
+        if (findCpuId == baseConfiguration->second.end())
+        {
+            std::cerr << "could not determine CPU ID for " << oemName << "\n";
+            continue;
+        }
+        int cpuId = mapbox::util::apply_visitor(VariantToIntVisitor(),
+                                                findCpuId->second);
+
+        auto directory = oemNamePath.parent_path().parent_path();
+        std::vector<fs::path> inputPaths;
+        if (!find_files(fs::path(directory),
+                        R"(peci-.+/hwmon/hwmon\d+/temp\d+_input$)", inputPaths,
+                        0))
+        {
+            std::cerr << "No temperature sensors in system\n";
+            continue;
+        }
+
+        // iterate through all found temp sensors
+        for (auto& inputPath : inputPaths)
+        {
+            auto inputPathStr = inputPath.string();
+            auto labelPath =
+                boost::replace_all_copy(inputPathStr, "input", "label");
+            std::ifstream labelFile(labelPath);
+            if (!labelFile.good())
+            {
+                std::cerr << "Failure reading " << labelPath << "\n";
+                continue;
+            }
+            std::string label;
+            std::getline(labelFile, label);
+            labelFile.close();
+            std::string sensorName = label + " CPU" + std::to_string(cpuId);
+            std::vector<thresholds::Threshold> sensorThresholds;
+            std::string labelHead = label.substr(0, label.find(" "));
+            if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds,
+                                           &labelHead))
+            {
+                continue;
+            }
+            if (!sensorThresholds.size())
+            {
+                if (!ParseThresholdsFromAttr(sensorThresholds, inputPathStr,
+                                             CPUSensor::SENSOR_SCALE_FACTOR))
+                {
+                    continue;
+                }
+            }
+            sensors[sensorName] = std::make_unique<CPUSensor>(
+                inputPathStr, sensorObjectType, objectServer, dbusConnection,
+                io, sensorName, std::move(sensorThresholds), *interfacePath);
+            if (DEBUG)
+                std::cout << "Mapped: " << inputPath << " to " << sensorName
+                          << "\n";
+        }
+    }
+}
+
+void reloadOverlay(const std::string& overlay)
+{
+    boost::process::child c1(DT_OVERLAY, "-d", OVERLAY_DIR, "-r", overlay);
+    c1.wait();
+    if (c1.exit_code())
+    {
+        if (DEBUG)
+        {
+            std::cout << "DTOverlay unload error with file " << overlay
+                      << ". error: " << c1.exit_code() << "\n";
+        }
+
+        /* fall through anyway */
+    }
+
+    boost::process::child c2(DT_OVERLAY, "-d", OVERLAY_DIR, overlay);
+    c2.wait();
+    if (c2.exit_code())
+    {
+        std::cerr << "DTOverlay load error with file " << overlay
+                  << ". error: " << c2.exit_code() << "\n";
+        return;
+    }
+}
+
+void detectCpu(boost::asio::deadline_timer& timer, boost::asio::io_service& io,
+               sdbusplus::asio::object_server& objectServer,
+               boost::container::flat_map<std::string,
+                                          std::unique_ptr<CPUSensor>>& sensors,
+               boost::container::flat_set<CPUConfig>& configs,
+               std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
+{
+    auto file = open(PECI_DEV, O_RDWR);
+    if (file < 0)
+    {
+        std::cerr << "unable to open " << PECI_DEV << "\n";
+        std::exit(EXIT_FAILURE);
+    }
+
+    size_t rescanDelaySeconds = 0;
+    bool keepPinging = false;
+    for (CPUConfig& config : configs)
+    {
+        State state;
+        struct peci_ping_msg msg;
+        msg.addr = config.addr;
+        if (!ioctl(file, PECI_IOC_PING, &msg))
+        {
+            bool dimmReady = false;
+            for (unsigned int rank = 0; rank < RANK_NUM_MAX; rank++)
+            {
+                struct peci_rd_pkg_cfg_msg msg;
+                msg.addr = config.addr;
+                msg.index = MBX_INDEX_DDR_DIMM_TEMP;
+                msg.param = rank;
+                msg.rx_len = 4;
+                if (!ioctl(file, PECI_IOC_RD_PKG_CFG, &msg))
+                {
+                    if (msg.pkg_config[0] || msg.pkg_config[1] ||
+                        msg.pkg_config[2])
+                    {
+                        dimmReady = true;
+                        break;
+                    }
+                }
+                else
+                {
+                    break;
+                }
+            }
+            if (dimmReady)
+            {
+                state = State::READY;
+            }
+            else
+            {
+                state = State::ON;
+            }
+        }
+        else
+        {
+            state = State::OFF;
+        }
+
+        if (config.state != state)
+        {
+            if (config.state == State::OFF)
+            {
+                reloadOverlay(config.ovName);
+            }
+            if (state != State::OFF)
+            {
+                if (state == State::ON)
+                {
+                    rescanDelaySeconds = 1;
+                }
+                else
+                {
+                    rescanDelaySeconds = 5;
+                }
+            }
+            config.state = state;
+        }
+
+        if (state != State::READY)
+        {
+            keepPinging = true;
+        }
+
+        if (DEBUG)
+            std::cout << config.ovName << ", state: " << state << "\n";
+    }
+
+    close(file);
+
+    if (rescanDelaySeconds)
+    {
+        std::this_thread::sleep_for(std::chrono::seconds(rescanDelaySeconds));
+        createSensors(io, objectServer, sensors, configs, dbusConnection);
+    }
+
+    if (keepPinging)
+    {
+        timer.expires_from_now(boost::posix_time::seconds(1));
+        timer.async_wait([&](const boost::system::error_code& ec) {
+            if (ec == boost::asio::error::operation_aborted)
+            {
+                /* we were canceled*/
+                return;
+            }
+            else if (ec)
+            {
+                std::cerr << "timer error\n";
+                return;
+            }
+            detectCpu(timer, io, objectServer, sensors, configs,
+                      dbusConnection);
+        });
+    }
+}
+
+void getCpuConfig(const std::shared_ptr<sdbusplus::asio::connection>& systemBus,
+                  boost::container::flat_set<CPUConfig>& configs)
+{
+    ManagedObjectType sensorConfigurations;
+    bool useCache = false;
+    // use new data the first time, then refresh
+    for (const char* type : SENSOR_TYPES)
+    {
+        if (!getSensorConfiguration(CONFIG_PREFIX + std::string(type),
+                                    systemBus, sensorConfigurations, useCache))
+        {
+            std::cerr
+                << "getCpuConfig: error communicating to entity manager\n";
+            return;
+        }
+        useCache = true;
+    }
+
+    // check PECI client addresses and DT overlay names from CPU configuration
+    // before starting ping operation
+    for (const char* type : SENSOR_TYPES)
+    {
+        for (const std::pair<sdbusplus::message::object_path, SensorData>&
+                 sensor : sensorConfigurations)
+        {
+            for (const std::pair<
+                     std::string,
+                     boost::container::flat_map<std::string, BasicVariantType>>&
+                     config : sensor.second)
+            {
+                if ((CONFIG_PREFIX + std::string(type)) != config.first)
+                {
+                    continue;
+                }
+
+                auto findAddress = config.second.find("Address");
+                if (findAddress == config.second.end())
+                {
+                    continue;
+                }
+                std::string addrStr = mapbox::util::apply_visitor(
+                    VariantToStringVisitor(), findAddress->second);
+                int addr = std::stoi(addrStr, 0, 16);
+
+                auto findName = config.second.find("Name");
+                if (findName == config.second.end())
+                {
+                    continue;
+                }
+                std::string nameRaw = mapbox::util::apply_visitor(
+                    VariantToStringVisitor(), findName->second);
+                std::string name =
+                    std::regex_replace(nameRaw, ILLEGAL_NAME_REGEX, "_");
+                std::string overlayName = name + "_" + type;
+
+                if (DEBUG)
+                {
+                    std::cout << "addr: " << addr << "\n";
+                    std::cout << "name: " << name << "\n";
+                    std::cout << "type: " << type << "\n";
+                    std::cout << "overlayName: " << overlayName << "\n";
+                }
+
+                configs.emplace(addr, overlayName, State::OFF);
+            }
+        }
+    }
+}
+
+int main(int argc, char** argv)
+{
+    boost::asio::io_service io;
+    auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
+    boost::container::flat_set<CPUConfig> configs;
+
+    systemBus->request_name("xyz.openbmc_project.CPUSensor");
+    sdbusplus::asio::object_server objectServer(systemBus);
+    boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>> sensors;
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
+    boost::asio::deadline_timer pingTimer(io);
+    getCpuConfig(systemBus, configs);
+    if (configs.size())
+    {
+        detectCpu(pingTimer, io, objectServer, sensors, configs, systemBus);
+    }
+
+    boost::asio::deadline_timer filterTimer(io);
+    std::function<void(sdbusplus::message::message&)> eventHandler =
+        [&](sdbusplus::message::message& message) {
+            if (message.is_method_error())
+            {
+                std::cerr << "callback method error\n";
+                return;
+            }
+            // this implicitly cancels the timer
+            filterTimer.expires_from_now(boost::posix_time::seconds(1));
+
+            filterTimer.async_wait([&](const boost::system::error_code& ec) {
+                if (ec == boost::asio::error::operation_aborted)
+                {
+                    /* we were canceled*/
+                    return;
+                }
+                else if (ec)
+                {
+                    std::cerr << "timer error\n";
+                    return;
+                }
+
+                getCpuConfig(systemBus, configs);
+
+                if (configs.size())
+                {
+                    detectCpu(pingTimer, io, objectServer, sensors, configs,
+                              systemBus);
+                }
+            });
+        };
+
+    for (const char* type : SENSOR_TYPES)
+    {
+        auto match = std::make_unique<sdbusplus::bus::match::match>(
+            static_cast<sdbusplus::bus::bus&>(*systemBus),
+            "type='signal',member='PropertiesChanged',path_namespace='" +
+                std::string(INVENTORY_PATH) + "',arg0namespace='" +
+                CONFIG_PREFIX + type + "'",
+            eventHandler);
+        matches.emplace_back(std::move(match));
+    }
+
+    io.run();
+}
diff --git a/sensors/src/FanMain.cpp b/sensors/src/FanMain.cpp
new file mode 100644
index 0000000..6818692
--- /dev/null
+++ b/sensors/src/FanMain.cpp
@@ -0,0 +1,290 @@
+/*
+// Copyright (c) 2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <PwmSensor.hpp>
+#include <TachSensor.hpp>
+#include <Utils.hpp>
+#include <VariantVisitors.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_set.hpp>
+#include <boost/lexical_cast.hpp>
+#include <experimental/filesystem>
+#include <fstream>
+#include <regex>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+static constexpr bool DEBUG = false;
+
+namespace fs = std::experimental::filesystem;
+static constexpr std::array<const char*, 1> SENSOR_TYPES = {
+    "xyz.openbmc_project.Configuration.AspeedFan"};
+static std::regex INPUT_REGEX(R"(fan(\d+)_input)");
+
+void createSensors(
+    boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+    boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>&
+        tachSensors,
+    boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>&
+        pwmSensors,
+    std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+    const std::unique_ptr<boost::container::flat_set<std::string>>&
+        sensorsChanged)
+{
+    bool firstScan = sensorsChanged == nullptr;
+    // use new data the first time, then refresh
+    ManagedObjectType sensorConfigurations;
+    bool useCache = false;
+    for (const char* type : SENSOR_TYPES)
+    {
+        if (!getSensorConfiguration(type, dbusConnection, sensorConfigurations,
+                                    useCache))
+        {
+            std::cerr << "error communicating to entity manager\n";
+            return;
+        }
+        useCache = true;
+    }
+    std::vector<fs::path> paths;
+    if (!find_files(fs::path("/sys/class/hwmon"), R"(fan\d+_input)", paths))
+    {
+        std::cerr << "No temperature sensors in system\n";
+        return;
+    }
+
+    // iterate through all found fan sensors, and try to match them with
+    // configuration
+    for (auto& path : paths)
+    {
+        std::smatch match;
+        std::string pathStr = path.string();
+
+        std::regex_search(pathStr, match, INPUT_REGEX);
+        std::string indexStr = *(match.begin() + 1);
+
+        auto directory = path.parent_path();
+        // convert to 0 based
+        size_t index = std::stoul(indexStr) - 1;
+
+        const char* baseType;
+        const SensorData* sensorData = nullptr;
+        const std::string* interfacePath = nullptr;
+        const std::pair<std::string, boost::container::flat_map<
+                                         std::string, BasicVariantType>>*
+            baseConfiguration = nullptr;
+        for (const std::pair<sdbusplus::message::object_path, SensorData>&
+                 sensor : sensorConfigurations)
+        {
+            // find the base of the configuration to see if indexes match
+            for (const char* type : SENSOR_TYPES)
+            {
+                auto sensorBaseFind = sensor.second.find(type);
+                if (sensorBaseFind != sensor.second.end())
+                {
+                    baseConfiguration = &(*sensorBaseFind);
+                    interfacePath = &(sensor.first.str);
+                    baseType = type;
+                    break;
+                }
+            }
+            if (baseConfiguration == nullptr)
+            {
+                continue;
+            }
+            auto connector =
+                sensor.second.find(baseType + std::string(".Connector"));
+            if (connector == sensor.second.end())
+            {
+                std::cerr << baseConfiguration->first << " missing connector\n";
+                continue;
+            }
+            auto findPwmIndex = connector->second.find("Pwm");
+            if (findPwmIndex == connector->second.end())
+            {
+                continue;
+            }
+            uint16_t pwmIndex = mapbox::util::apply_visitor(
+                VariantToUnsignedIntVisitor(), findPwmIndex->second);
+            auto oemNamePath = directory.string() + R"(/of_node/oemname)" +
+                               std::to_string(pwmIndex);
+
+            if (DEBUG)
+                std::cout << "Checking path " << oemNamePath << "\n";
+            std::ifstream nameFile(oemNamePath);
+            if (!nameFile.good())
+            {
+                continue;
+            }
+            std::string oemName;
+            std::getline(nameFile, oemName);
+            nameFile.close();
+            if (!oemName.size())
+            {
+                // shouldn't have an empty name file
+                continue;
+            }
+            oemName.pop_back(); // remove trailing null
+            auto findIndex = baseConfiguration->second.find("Index");
+            if (findIndex == baseConfiguration->second.end())
+            {
+                std::cerr << baseConfiguration->first << " missing index\n";
+                continue;
+            }
+            unsigned int configIndex = mapbox::util::apply_visitor(
+                VariantToUnsignedIntVisitor(), findIndex->second);
+
+            if (configIndex != index)
+            {
+                continue;
+            }
+            // now that the indexes match, verify the connector
+            auto findConnectorName = connector->second.find("Name");
+            if (findConnectorName == connector->second.end())
+            {
+                continue;
+            }
+            std::string connectorName = mapbox::util::apply_visitor(
+                VariantToStringVisitor(), findConnectorName->second);
+            boost::replace_all(connectorName, " ", "_");
+            if (connectorName == oemName)
+            {
+                sensorData = &(sensor.second);
+                break;
+            }
+        }
+        if (sensorData == nullptr)
+        {
+            std::cerr << "failed to find match for " << path.string() << "\n";
+            continue;
+        }
+
+        auto findSensorName = baseConfiguration->second.find("Name");
+        if (findSensorName == baseConfiguration->second.end())
+        {
+            std::cerr << "could not determine configuration name for "
+                      << path.string() << "\n";
+            continue;
+        }
+        std::string sensorName =
+            sdbusplus::message::variant_ns::get<std::string>(
+                findSensorName->second);
+        // on rescans, only update sensors we were signaled by
+        auto findSensor = tachSensors.find(sensorName);
+        if (!firstScan && findSensor != tachSensors.end())
+        {
+            bool found = false;
+            for (auto it = sensorsChanged->begin(); it != sensorsChanged->end();
+                 it++)
+            {
+                if (boost::ends_with(*it, findSensor->second->name))
+                {
+                    sensorsChanged->erase(it);
+                    findSensor->second = nullptr;
+                    found = true;
+                    break;
+                }
+            }
+            if (!found)
+            {
+                continue;
+            }
+        }
+        std::vector<thresholds::Threshold> sensorThresholds;
+        if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds))
+        {
+            std::cerr << "error populating thresholds for " << sensorName
+                      << "\n";
+        }
+
+        tachSensors[sensorName] = std::make_unique<TachSensor>(
+            path.string(), objectServer, dbusConnection, io, sensorName,
+            std::move(sensorThresholds), *interfacePath);
+    }
+    std::vector<fs::path> pwms;
+    if (!find_files(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwms))
+    {
+        std::cerr << "No pwm in system\n";
+        return;
+    }
+    for (const fs::path& pwm : pwms)
+    {
+        // only add new elements
+        pwmSensors.insert(std::pair<std::string, std::unique_ptr<PwmSensor>>(
+            pwm.string(),
+            std::make_unique<PwmSensor>(pwm.string(), objectServer)));
+    }
+}
+
+int main(int argc, char** argv)
+{
+    boost::asio::io_service io;
+    auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
+    systemBus->request_name("xyz.openbmc_project.FanSensor");
+    sdbusplus::asio::object_server objectServer(systemBus);
+    boost::container::flat_map<std::string, std::unique_ptr<TachSensor>>
+        tachSensors;
+    boost::container::flat_map<std::string, std::unique_ptr<PwmSensor>>
+        pwmSensors;
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
+    std::unique_ptr<boost::container::flat_set<std::string>> sensorsChanged =
+        std::make_unique<boost::container::flat_set<std::string>>();
+
+    io.post([&]() {
+        createSensors(io, objectServer, tachSensors, pwmSensors, systemBus,
+                      nullptr);
+    });
+
+    boost::asio::deadline_timer filterTimer(io);
+    std::function<void(sdbusplus::message::message&)> eventHandler =
+        [&](sdbusplus::message::message& message) {
+            if (message.is_method_error())
+            {
+                std::cerr << "callback method error\n";
+                return;
+            }
+            sensorsChanged->insert(message.get_path());
+            // this implicitly cancels the timer
+            filterTimer.expires_from_now(boost::posix_time::seconds(1));
+
+            filterTimer.async_wait([&](const boost::system::error_code& ec) {
+                if (ec == boost::asio::error::operation_aborted)
+                {
+                    /* we were canceled*/
+                    return;
+                }
+                else if (ec)
+                {
+                    std::cerr << "timer error\n";
+                    return;
+                }
+                createSensors(io, objectServer, tachSensors, pwmSensors,
+                              systemBus, sensorsChanged);
+            });
+        };
+
+    for (const char* type : SENSOR_TYPES)
+    {
+        auto match = std::make_unique<sdbusplus::bus::match::match>(
+            static_cast<sdbusplus::bus::bus&>(*systemBus),
+            "type='signal',member='PropertiesChanged',path_namespace='" +
+                std::string(INVENTORY_PATH) + "',arg0namespace='" + type + "'",
+            eventHandler);
+        matches.emplace_back(std::move(match));
+    }
+
+    io.run();
+}
diff --git a/sensors/src/HwmonTempMain.cpp b/sensors/src/HwmonTempMain.cpp
new file mode 100644
index 0000000..3c49771
--- /dev/null
+++ b/sensors/src/HwmonTempMain.cpp
@@ -0,0 +1,235 @@
+/*
+// Copyright (c) 2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <HwmonTempSensor.hpp>
+#include <Utils.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/container/flat_set.hpp>
+#include <experimental/filesystem>
+#include <fstream>
+#include <regex>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+
+static constexpr bool DEBUG = false;
+
+namespace fs = std::experimental::filesystem;
+static constexpr std::array<const char*, 2> SENSOR_TYPES = {
+    "xyz.openbmc_project.Configuration.TMP75",
+    "xyz.openbmc_project.Configuration.TMP421"};
+static std::regex INPUT_REGEX(R"(temp(\d+)_input)");
+
+void createSensors(
+    boost::asio::io_service& io, sdbusplus::asio::object_server& objectServer,
+    boost::container::flat_map<std::string, std::unique_ptr<HwmonTempSensor>>&
+        sensors,
+    std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+    const std::unique_ptr<boost::container::flat_set<std::string>>&
+        sensorsChanged)
+{
+    bool firstScan = sensorsChanged == nullptr;
+    // use new data the first time, then refresh
+    ManagedObjectType sensorConfigurations;
+    bool useCache = false;
+    for (const char* type : SENSOR_TYPES)
+    {
+        if (!getSensorConfiguration(type, dbusConnection, sensorConfigurations,
+                                    useCache))
+        {
+            std::cerr << "error communicating to entity manager\n";
+            return;
+        }
+        useCache = true;
+    }
+    std::vector<fs::path> paths;
+    if (!find_files(fs::path("/sys/class/hwmon"), R"(temp\d+_input)", paths))
+    {
+        std::cerr << "No temperature sensors in system\n";
+        return;
+    }
+
+    // iterate through all found temp sensors, and try to match them with
+    // configuration
+    for (auto& path : paths)
+    {
+        std::smatch match;
+        std::string pathStr = path.string();
+
+        std::regex_search(pathStr, match, INPUT_REGEX);
+        std::string index = *(match.begin() + 1);
+
+        auto directory = path.parent_path();
+        auto oem_name_path = directory.string() + R"(/of_node/oemname)" + index;
+
+        if (DEBUG)
+            std::cout << "Checking path " << oem_name_path << "\n";
+        std::ifstream nameFile(oem_name_path);
+        if (!nameFile.good())
+        {
+            std::cerr << "Failure reading " << oem_name_path << "\n";
+            continue;
+        }
+        std::string oemName;
+        std::getline(nameFile, oemName);
+        nameFile.close();
+        if (!oemName.size())
+        {
+            // shouldn't have an empty name file
+            continue;
+        }
+        oemName.pop_back(); // remove trailing null
+
+        const SensorData* sensorData = nullptr;
+        const std::string* interfacePath = nullptr;
+        for (const std::pair<sdbusplus::message::object_path, SensorData>&
+                 sensor : sensorConfigurations)
+        {
+            if (!boost::ends_with(sensor.first.str, oemName))
+            {
+                continue;
+            }
+            sensorData = &(sensor.second);
+            interfacePath = &(sensor.first.str);
+            break;
+        }
+        if (sensorData == nullptr)
+        {
+            std::cerr << "failed to find match for " << oemName << "\n";
+            continue;
+        }
+        const std::pair<std::string, boost::container::flat_map<
+                                         std::string, BasicVariantType>>*
+            baseConfiguration = nullptr;
+        const char* sensorType = nullptr;
+        for (const char* type : SENSOR_TYPES)
+        {
+            auto sensorBase = sensorData->find(type);
+            if (sensorBase != sensorData->end())
+            {
+                baseConfiguration = &(*sensorBase);
+                sensorType = type;
+                break;
+            }
+        }
+
+        if (baseConfiguration == nullptr)
+        {
+            std::cerr << "error finding base configuration for" << oemName
+                      << "\n";
+            continue;
+        }
+
+        auto findSensorName = baseConfiguration->second.find("Name");
+        if (findSensorName == baseConfiguration->second.end())
+        {
+            std::cerr << "could not determine configuration name for "
+                      << oemName << "\n";
+            continue;
+        }
+        std::string sensorName =
+            sdbusplus::message::variant_ns::get<std::string>(
+                findSensorName->second);
+        // on rescans, only update sensors we were signaled by
+        auto findSensor = sensors.find(sensorName);
+        if (!firstScan && findSensor != sensors.end())
+        {
+            bool found = false;
+            for (auto it = sensorsChanged->begin(); it != sensorsChanged->end();
+                 it++)
+            {
+                if (boost::ends_with(*it, findSensor->second->name))
+                {
+                    sensorsChanged->erase(it);
+                    findSensor->second = nullptr;
+                    found = true;
+                    break;
+                }
+            }
+            if (!found)
+            {
+                continue;
+            }
+        }
+        std::vector<thresholds::Threshold> sensorThresholds;
+        if (!ParseThresholdsFromConfig(*sensorData, sensorThresholds))
+        {
+            std::cerr << "error populating thresholds for " << sensorName
+                      << "\n";
+        }
+
+        sensors[sensorName] = std::make_unique<HwmonTempSensor>(
+            path.string(), sensorType, objectServer, dbusConnection, io,
+            sensorName, std::move(sensorThresholds), *interfacePath);
+    }
+}
+
+int main(int argc, char** argv)
+{
+    boost::asio::io_service io;
+    auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
+    systemBus->request_name("xyz.openbmc_project.HwmonTempSensor");
+    sdbusplus::asio::object_server objectServer(systemBus);
+    boost::container::flat_map<std::string, std::unique_ptr<HwmonTempSensor>>
+        sensors;
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
+    std::unique_ptr<boost::container::flat_set<std::string>> sensorsChanged =
+        std::make_unique<boost::container::flat_set<std::string>>();
+
+    io.post([&]() {
+        createSensors(io, objectServer, sensors, systemBus, nullptr);
+    });
+
+    boost::asio::deadline_timer filterTimer(io);
+    std::function<void(sdbusplus::message::message&)> eventHandler =
+        [&](sdbusplus::message::message& message) {
+            if (message.is_method_error())
+            {
+                std::cerr << "callback method error\n";
+                return;
+            }
+            sensorsChanged->insert(message.get_path());
+            // this implicitly cancels the timer
+            filterTimer.expires_from_now(boost::posix_time::seconds(1));
+
+            filterTimer.async_wait([&](const boost::system::error_code& ec) {
+                if (ec == boost::asio::error::operation_aborted)
+                {
+                    /* we were canceled*/
+                    return;
+                }
+                else if (ec)
+                {
+                    std::cerr << "timer error\n";
+                    return;
+                }
+                createSensors(io, objectServer, sensors, systemBus,
+                              sensorsChanged);
+            });
+        };
+
+    for (const char* type : SENSOR_TYPES)
+    {
+        auto match = std::make_unique<sdbusplus::bus::match::match>(
+            static_cast<sdbusplus::bus::bus&>(*systemBus),
+            "type='signal',member='PropertiesChanged',path_namespace='" +
+                std::string(INVENTORY_PATH) + "',arg0namespace='" + type + "'",
+            eventHandler);
+        matches.emplace_back(std::move(match));
+    }
+
+    io.run();
+}
diff --git a/sensors/src/HwmonTempSensor.cpp b/sensors/src/HwmonTempSensor.cpp
new file mode 100644
index 0000000..c1db504
--- /dev/null
+++ b/sensors/src/HwmonTempSensor.cpp
@@ -0,0 +1,304 @@
+/*
+// Copyright (c) 2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <unistd.h>
+
+#include <HwmonTempSensor.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <iostream>
+#include <limits>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <string>
+
+static constexpr unsigned int SENSOR_POLL_MS = 500;
+static constexpr unsigned int SENSOR_SCALE_FACTOR = 1000;
+static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+
+HwmonTempSensor::HwmonTempSensor(
+    const std::string &path, const std::string &objectType,
+    sdbusplus::asio::object_server &objectServer,
+    std::shared_ptr<sdbusplus::asio::connection> &conn,
+    boost::asio::io_service &io, const std::string &sensor_name,
+    std::vector<thresholds::Threshold> &&_thresholds,
+    const std::string &sensorConfiguration) :
+    path(path),
+    objectType(objectType), configuration(sensorConfiguration),
+    objServer(objectServer),
+    name(boost::replace_all_copy(sensor_name, " ", "_")),
+    thresholds(std::move(_thresholds)),
+    sensor_interface(objectServer.add_interface(
+        "/xyz/openbmc_project/sensors/temperature/" + name,
+        "xyz.openbmc_project.Sensor.Value")),
+    input_dev(io, open(path.c_str(), O_RDONLY)), wait_timer(io),
+    value(std::numeric_limits<double>::quiet_NaN()), err_count(0),
+    // todo, get these from config
+    max_value(127), min_value(-128)
+{
+    if (thresholds::HasWarningInterface(thresholds))
+    {
+        threshold_interface_warning = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/temperature/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Warning");
+    }
+    if (thresholds::HasCriticalInterface(thresholds))
+    {
+        threshold_interface_critical = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/temperature/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Critical");
+    }
+    set_initial_properties(conn);
+    setup_read();
+}
+
+HwmonTempSensor::~HwmonTempSensor()
+{
+    // close the input dev to cancel async operations
+    input_dev.close();
+    wait_timer.cancel();
+    objServer.remove_interface(threshold_interface_warning);
+    objServer.remove_interface(threshold_interface_critical);
+    objServer.remove_interface(sensor_interface);
+}
+
+void HwmonTempSensor::setup_read(void)
+{
+    boost::asio::async_read_until(
+        input_dev, read_buf, '\n',
+        [&](const boost::system::error_code &ec,
+            std::size_t /*bytes_transfered*/) { handle_response(ec); });
+}
+
+void HwmonTempSensor::handle_response(const boost::system::error_code &err)
+{
+    if (err == boost::system::errc::bad_file_descriptor)
+    {
+        return; // we're being destroyed
+    }
+    std::istream response_stream(&read_buf);
+    if (!err)
+    {
+        std::string response;
+        std::getline(response_stream, response);
+        try
+        {
+            float nvalue = std::stof(response);
+
+            nvalue /= SENSOR_SCALE_FACTOR;
+            if (nvalue != value)
+            {
+                update_value(nvalue);
+            }
+            err_count = 0;
+        }
+        catch (const std::invalid_argument &)
+        {
+            err_count++;
+        }
+    }
+    else
+    {
+        std::cerr << "Failure to read sensor " << name << " at " << path
+                  << "\n";
+        err_count++;
+    }
+    // only send value update once
+    if (err_count == WARN_AFTER_ERROR_COUNT)
+    {
+        update_value(0);
+    }
+    response_stream.clear();
+    input_dev.close();
+    int fd = open(path.c_str(), O_RDONLY);
+    if (fd <= 0)
+    {
+        return; // we're no longer valid
+    }
+    input_dev.assign(fd);
+    wait_timer.expires_from_now(
+        boost::posix_time::milliseconds(SENSOR_POLL_MS));
+    ;
+    wait_timer.async_wait([&](const boost::system::error_code &ec) {
+        if (ec == boost::asio::error::operation_aborted)
+        {
+            return; // we're being canceled
+        }
+        setup_read();
+    });
+}
+
+void HwmonTempSensor::check_thresholds(void)
+{
+    if (thresholds.empty())
+        return;
+    for (auto threshold : thresholds)
+    {
+        if (threshold.direction == thresholds::Direction::HIGH)
+        {
+            if (value > threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+        else
+        {
+            if (value < threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+    }
+}
+
+void HwmonTempSensor::update_value(const double &new_value)
+{
+    sensor_interface->set_property("Value", new_value);
+    value = new_value;
+    check_thresholds();
+}
+
+void HwmonTempSensor::assert_thresholds(thresholds::Level level,
+                                        thresholds::Direction direction,
+                                        bool assert)
+{
+    std::string property;
+    std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
+    if (level == thresholds::Level::WARNING &&
+        direction == thresholds::Direction::HIGH)
+    {
+        property = "WarningAlarmHigh";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::WARNING &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "WarningAlarmLow";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::HIGH)
+    {
+        property = "CriticalAlarmHigh";
+        interface = threshold_interface_critical;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "CriticalAlarmLow";
+        interface = threshold_interface_critical;
+    }
+    else
+    {
+        std::cerr << "Unknown threshold, level " << level << "direction "
+                  << direction << "\n";
+        return;
+    }
+    if (!interface)
+    {
+        std::cout << "trying to set uninitialized interface\n";
+        return;
+    }
+    interface->set_property(property, assert);
+}
+
+void HwmonTempSensor::set_initial_properties(
+    std::shared_ptr<sdbusplus::asio::connection> &conn)
+{
+    // todo, get max and min from configuration
+    sensor_interface->register_property("MaxValue", max_value);
+    sensor_interface->register_property("MinValue", min_value);
+    sensor_interface->register_property("Value", value);
+
+    for (auto &threshold : thresholds)
+    {
+        std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
+        std::string level;
+        std::string alarm;
+        if (threshold.level == thresholds::Level::CRITICAL)
+        {
+            iface = threshold_interface_critical;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "CriticalHigh";
+                alarm = "CriticalAlarmHigh";
+            }
+            else
+            {
+                level = "CriticalLow";
+                alarm = "CriticalAlarmLow";
+            }
+        }
+        else if (threshold.level == thresholds::Level::WARNING)
+        {
+            iface = threshold_interface_warning;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "WarningHigh";
+                alarm = "WarningAlarmHigh";
+            }
+            else
+            {
+                level = "WarningLow";
+                alarm = "WarningAlarmLow";
+            }
+        }
+        else
+        {
+            std::cerr << "Unknown threshold level" << threshold.level << "\n";
+            continue;
+        }
+        if (!iface)
+        {
+            std::cout << "trying to set uninitialized interface\n";
+            continue;
+        }
+        iface->register_property(
+            level, threshold.value,
+            [&](const double &request, double &oldValue) {
+                oldValue = request; // todo, just let the config do this?
+                threshold.value = request;
+                thresholds::persistThreshold(configuration, objectType,
+                                             threshold, conn);
+                return 1;
+            });
+        iface->register_property(alarm, false);
+    }
+    if (!sensor_interface->initialize())
+    {
+        std::cerr << "error initializing value interface\n";
+    }
+    if (threshold_interface_warning &&
+        !threshold_interface_warning->initialize())
+    {
+        std::cerr << "error initializing warning threshold interface\n";
+    }
+
+    if (threshold_interface_critical &&
+        !threshold_interface_critical->initialize())
+    {
+        std::cerr << "error initializing critical threshold interface\n";
+    }
+}
diff --git a/sensors/src/PwmSensor.cpp b/sensors/src/PwmSensor.cpp
new file mode 100644
index 0000000..11d635f
--- /dev/null
+++ b/sensors/src/PwmSensor.cpp
@@ -0,0 +1,129 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#include <PwmSensor.hpp>
+#include <fstream>
+#include <iostream>
+#include <sdbusplus/asio/object_server.hpp>
+
+constexpr size_t pwmMax = 255;
+constexpr size_t pwmMin = 0;
+
+PwmSensor::PwmSensor(const std::string& sysPath,
+                     sdbusplus::asio::object_server& objectServer) :
+    sysPath(sysPath),
+    objectServer(objectServer)
+{
+    // strip off index from path
+    name = "Pwm_" + sysPath.substr(sysPath.find_last_of("pwm") + 1);
+
+    // add interface under sensor and Control.FanPwm as Control is used
+    // in obmc project, also add sensor so it can be viewed as a sensor
+    sensorInterface = objectServer.add_interface(
+        "/xyz/openbmc_project/sensors/fan_pwm/" + name,
+        "xyz.openbmc_project.Sensor.Value");
+    uint32_t pwmValue = getValue(false);
+    double fValue = 100.0 * (static_cast<float>(pwmValue) / pwmMax);
+    sensorInterface->register_property(
+        "Value", fValue,
+        [this](const double& req, double& resp) {
+            if (req > 100 || req < 0)
+            {
+                throw std::runtime_error("Value out of range");
+                return -1;
+            }
+            double value = (req / 100) * pwmMax;
+            setValue(static_cast<int>(value));
+            resp = req;
+            return 1;
+        },
+        [this](double& curVal) {
+            float value = 100.0 * (static_cast<float>(getValue()) / pwmMax);
+            curVal = value;
+            return curVal;
+        });
+    // pwm sensor interface is in percent
+    sensorInterface->register_property("MaxValue", static_cast<int64_t>(100));
+    sensorInterface->register_property("MinValue", static_cast<int64_t>(0));
+
+    controlInterface = objectServer.add_interface(
+        "/xyz/openbmc_project/control/fanpwm/" + name,
+        "xyz.openbmc_project.Control.FanPwm");
+    controlInterface->register_property(
+        "Target", static_cast<uint64_t>(pwmValue),
+        [this](const uint64_t& req, uint64_t& resp) {
+            if (req > pwmMax || req < pwmMin)
+            {
+                throw std::runtime_error("Value out of range");
+                return -1;
+            }
+            setValue(req);
+            resp = req;
+            return 1;
+        },
+        [this](uint64_t& curVal) {
+            curVal = getValue();
+            return curVal;
+        });
+    sensorInterface->initialize();
+    controlInterface->initialize();
+}
+PwmSensor::~PwmSensor()
+{
+    objectServer.remove_interface(sensorInterface);
+    objectServer.remove_interface(controlInterface);
+}
+
+void PwmSensor::setValue(uint32_t value)
+{
+    std::ofstream ref(sysPath);
+    if (!ref.good())
+    {
+        throw std::runtime_error("Bad Write File");
+        return;
+    }
+    ref << value;
+}
+
+// on success returns pwm, on failure throws except on initialization, where it
+// prints an error and returns 0
+uint32_t PwmSensor::getValue(bool errThrow)
+{
+    std::ifstream ref(sysPath);
+    if (!ref.good())
+    {
+        return -1;
+    }
+    std::string line;
+    if (!std::getline(ref, line))
+    {
+        return -1;
+    }
+    try
+    {
+        uint32_t value = std::stoi(line);
+        return value;
+    }
+    catch (std::invalid_argument)
+    {
+        std::cerr << "Error reading pwm at " << sysPath << "\n";
+        // throw if not initial read to be caught by dbus bindings
+        if (errThrow)
+        {
+            throw std::runtime_error("Bad Read");
+        }
+    }
+    return 0;
+}
diff --git a/sensors/src/TachSensor.cpp b/sensors/src/TachSensor.cpp
new file mode 100644
index 0000000..91f0545
--- /dev/null
+++ b/sensors/src/TachSensor.cpp
@@ -0,0 +1,312 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <unistd.h>
+
+#include <TachSensor.hpp>
+#include <Utils.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <iostream>
+#include <limits>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
+#include <string>
+
+static constexpr unsigned int PWM_POLL_MS = 500;
+static constexpr size_t WARN_AFTER_ERROR_COUNT = 10;
+
+TachSensor::TachSensor(const std::string &path,
+                       sdbusplus::asio::object_server &objectServer,
+                       std::shared_ptr<sdbusplus::asio::connection> &conn,
+                       boost::asio::io_service &io, const std::string &fanName,
+                       std::vector<thresholds::Threshold> &&_thresholds,
+                       const std::string &sensorConfiguration) :
+    path(path),
+    objServer(objectServer), dbusConnection(conn),
+    name(boost::replace_all_copy(fanName, " ", "_")),
+    configuration(sensorConfiguration), thresholds(std::move(_thresholds)),
+    sensor_interface(objectServer.add_interface(
+        "/xyz/openbmc_project/sensors/fan_tach/" + name,
+        "xyz.openbmc_project.Sensor.Value")),
+    input_dev(io, open(path.c_str(), O_RDONLY)), wait_timer(io),
+    value(std::numeric_limits<double>::quiet_NaN()), err_count(0),
+    // todo, get these from config
+    max_value(25000), min_value(0)
+{
+    if (thresholds::HasWarningInterface(thresholds))
+    {
+        threshold_interface_warning = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/fan_tach/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Warning");
+    }
+    if (thresholds::HasCriticalInterface(thresholds))
+    {
+        threshold_interface_critical = objectServer.add_interface(
+            "/xyz/openbmc_project/sensors/fan_tach/" + name,
+            "xyz.openbmc_project.Sensor.Threshold.Critical");
+    }
+    set_initial_properties(conn);
+    isPowerOn(dbusConnection); // first call initializes
+    setup_read();
+}
+
+TachSensor::~TachSensor()
+{
+    // close the input dev to cancel async operations
+    input_dev.close();
+    wait_timer.cancel();
+    objServer.remove_interface(threshold_interface_warning);
+    objServer.remove_interface(threshold_interface_critical);
+    objServer.remove_interface(sensor_interface);
+}
+
+void TachSensor::setup_read(void)
+{
+    boost::asio::async_read_until(
+        input_dev, read_buf, '\n',
+        [&](const boost::system::error_code &ec,
+            std::size_t /*bytes_transfered*/) { handle_response(ec); });
+}
+
+void TachSensor::handle_response(const boost::system::error_code &err)
+{
+    if (err == boost::system::errc::bad_file_descriptor)
+    {
+        return; // we're being destroyed
+    }
+    std::istream response_stream(&read_buf);
+    if (!err)
+    {
+        std::string response;
+        try
+        {
+            std::getline(response_stream, response);
+            float nvalue = std::stof(response);
+            response_stream.clear();
+            if (nvalue != value)
+            {
+                update_value(nvalue);
+            }
+            err_count = 0;
+        }
+        catch (const std::invalid_argument &)
+        {
+            err_count++;
+        }
+    }
+    else
+    {
+
+        err_count++;
+    }
+    // only send value update once
+    if (err_count == WARN_AFTER_ERROR_COUNT)
+    {
+        // only an error if power is on
+        if (isPowerOn(dbusConnection))
+        {
+            std::cerr << "Failure to read sensor " << name << " at " << path
+                      << "\n";
+            update_value(0);
+        }
+        else
+        {
+            err_count = 0; // check power again in 10 cycles
+            sensor_interface->set_property(
+                "Value", std::numeric_limits<double>::quiet_NaN());
+        }
+    }
+    response_stream.clear();
+    input_dev.close();
+    int fd = open(path.c_str(), O_RDONLY);
+    if (fd <= 0)
+    {
+        return; // we're no longer valid
+    }
+    input_dev.assign(fd);
+    wait_timer.expires_from_now(boost::posix_time::milliseconds(PWM_POLL_MS));
+    wait_timer.async_wait([&](const boost::system::error_code &ec) {
+        if (ec == boost::asio::error::operation_aborted)
+        {
+            return; // we're being canceled
+        }
+        setup_read();
+    });
+}
+
+void TachSensor::check_thresholds(void)
+{
+    if (thresholds.empty())
+        return;
+    for (auto &threshold : thresholds)
+    {
+        if (threshold.direction == thresholds::Direction::HIGH)
+        {
+            if (value > threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+        else
+        {
+            if (value < threshold.value)
+            {
+                assert_thresholds(threshold.level, threshold.direction, true);
+            }
+            else
+            {
+                assert_thresholds(threshold.level, threshold.direction, false);
+            }
+        }
+    }
+}
+
+void TachSensor::update_value(const double &new_value)
+{
+    sensor_interface->set_property("Value", new_value);
+    value = new_value;
+    check_thresholds();
+}
+
+void TachSensor::assert_thresholds(thresholds::Level level,
+                                   thresholds::Direction direction, bool assert)
+{
+    std::string property;
+    std::shared_ptr<sdbusplus::asio::dbus_interface> interface;
+    if (level == thresholds::Level::WARNING &&
+        direction == thresholds::Direction::HIGH)
+    {
+        property = "WarningAlarmHigh";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::WARNING &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "WarningAlarmLow";
+        interface = threshold_interface_warning;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::HIGH)
+    {
+        property = "CriticalAlarmHigh";
+        interface = threshold_interface_critical;
+    }
+    else if (level == thresholds::Level::CRITICAL &&
+             direction == thresholds::Direction::LOW)
+    {
+        property = "CriticalAlarmLow";
+        interface = threshold_interface_critical;
+    }
+    else
+    {
+        std::cerr << "Unknown threshold, level " << level << "direction "
+                  << direction << "\n";
+        return;
+    }
+    if (!interface)
+    {
+        std::cout << "trying to set uninitialized interface\n";
+        return;
+    }
+    interface->set_property(property, assert);
+}
+
+void TachSensor::set_initial_properties(
+    std::shared_ptr<sdbusplus::asio::connection> &conn)
+{
+    // todo, get max and min from configuration
+    sensor_interface->register_property("MaxValue", max_value);
+    sensor_interface->register_property("MinValue", min_value);
+    sensor_interface->register_property("Value", value);
+
+    for (auto &threshold : thresholds)
+    {
+        std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
+        std::string level;
+        std::string alarm;
+        if (threshold.level == thresholds::Level::CRITICAL)
+        {
+            iface = threshold_interface_critical;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "CriticalHigh";
+                alarm = "CriticalAlarmHigh";
+            }
+            else
+            {
+                level = "CriticalLow";
+                alarm = "CriticalAlarmLow";
+            }
+        }
+        else if (threshold.level == thresholds::Level::WARNING)
+        {
+            iface = threshold_interface_warning;
+            if (threshold.direction == thresholds::Direction::HIGH)
+            {
+                level = "WarningHigh";
+                alarm = "WarningAlarmHigh";
+            }
+            else
+            {
+                level = "WarningLow";
+                alarm = "WarningAlarmLow";
+            }
+        }
+        else
+        {
+            std::cerr << "Unknown threshold level" << threshold.level << "\n";
+            continue;
+        }
+        if (!iface)
+        {
+            std::cout << "trying to set uninitialized interface\n";
+            continue;
+        }
+        iface->register_property(
+            level, threshold.value,
+            [&](const double &request, double &oldValue) {
+                oldValue = request; // todo, just let the config do this?
+                threshold.value = request;
+                thresholds::persistThreshold(
+                    configuration,
+                    "xyz.openbmc_project.Configuration.AspeedFan", threshold,
+                    conn);
+                return 1;
+            });
+        iface->register_property(alarm, false);
+    }
+    if (!sensor_interface->initialize())
+    {
+        std::cerr << "error initializing value interface\n";
+    }
+    if (threshold_interface_warning &&
+        !threshold_interface_warning->initialize())
+    {
+        std::cerr << "error initializing warning threshold interface\n";
+    }
+
+    if (threshold_interface_critical &&
+        !threshold_interface_critical->initialize())
+    {
+        std::cerr << "error initializing critical threshold interface\n";
+    }
+}
diff --git a/sensors/src/Thresholds.cpp b/sensors/src/Thresholds.cpp
new file mode 100644
index 0000000..d31f487
--- /dev/null
+++ b/sensors/src/Thresholds.cpp
@@ -0,0 +1,224 @@
+#include <Thresholds.hpp>
+#include <VariantVisitors.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/lexical_cast.hpp>
+#include <fstream>
+#include <iostream>
+
+static constexpr bool DEBUG = false;
+constexpr size_t MAX_THRESHOLDS = 4;
+
+namespace thresholds
+{
+unsigned int toBusValue(const Level &level)
+{
+    switch (level)
+    {
+        case (Level::WARNING):
+        {
+            return 0;
+        }
+        case (Level::CRITICAL):
+        {
+            return 1;
+        }
+        default:
+        {
+            return -1;
+        }
+    }
+}
+
+std::string toBusValue(const Direction &direction)
+{
+    switch (direction)
+    {
+        case (Direction::LOW):
+        {
+            return "less than";
+        }
+        case (Direction::HIGH):
+        {
+            return "greater than";
+        }
+        default:
+        {
+            return "err";
+        }
+    }
+}
+
+bool ParseThresholdsFromConfig(
+    const SensorData &sensorData,
+    std::vector<thresholds::Threshold> &thresholdVector,
+    const std::string *matchLabel)
+{
+    for (const auto &item : sensorData)
+    {
+        if (item.first.find("Thresholds") == std::string::npos)
+        {
+            continue;
+        }
+        if (matchLabel != nullptr)
+        {
+            auto labelFind = item.second.find("Label");
+            if (labelFind == item.second.end())
+                continue;
+            if (mapbox::util::apply_visitor(VariantToStringVisitor(),
+                                            labelFind->second) != *matchLabel)
+                continue;
+        }
+        auto directionFind = item.second.find("Direction");
+        auto severityFind = item.second.find("Severity");
+        auto valueFind = item.second.find("Value");
+        if (valueFind == item.second.end() ||
+            severityFind == item.second.end() ||
+            directionFind == item.second.end())
+        {
+            std::cerr << "Malformed threshold in configuration\n";
+            return false;
+        }
+        Level level;
+        Direction direction;
+        if (mapbox::util::apply_visitor(VariantToUnsignedIntVisitor(),
+                                        severityFind->second) == 0)
+        {
+            level = Level::WARNING;
+        }
+        else
+        {
+            level = Level::CRITICAL;
+        }
+        if (mapbox::util::apply_visitor(VariantToStringVisitor(),
+                                        directionFind->second) == "less than")
+        {
+            direction = Direction::LOW;
+        }
+        else
+        {
+            direction = Direction::HIGH;
+        }
+        float val = mapbox::util::apply_visitor(VariantToFloatVisitor(),
+                                                valueFind->second);
+
+        thresholdVector.emplace_back(level, direction, val);
+    }
+    return true;
+}
+
+void persistThreshold(const std::string &path, const std::string &baseInterface,
+                      const thresholds::Threshold &threshold,
+                      std::shared_ptr<sdbusplus::asio::connection> &conn)
+{
+    for (int ii = 0; ii < MAX_THRESHOLDS; ii++)
+    {
+        std::string thresholdInterface =
+            baseInterface + ".Thresholds" + std::to_string(ii);
+        conn->async_method_call(
+            [&, path, threshold, thresholdInterface](
+                const boost::system::error_code &ec,
+                const boost::container::flat_map<std::string, BasicVariantType>
+                    &result) {
+                if (ec)
+                {
+                    return; // threshold not supported
+                }
+
+                auto directionFind = result.find("Direction");
+                auto severityFind = result.find("Severity");
+                auto valueFind = result.find("Value");
+                if (valueFind == result.end() || severityFind == result.end() ||
+                    directionFind == result.end())
+                {
+                    std::cerr << "Malformed threshold in configuration\n";
+                    return;
+                }
+                unsigned int level = mapbox::util::apply_visitor(
+                    VariantToUnsignedIntVisitor(), severityFind->second);
+
+                std::string dir = mapbox::util::apply_visitor(
+                    VariantToStringVisitor(), directionFind->second);
+                if ((toBusValue(threshold.level) != level) ||
+                    (toBusValue(threshold.direction) != dir))
+                {
+                    return; // not the droid we're looking for
+                }
+
+                sdbusplus::message::variant<double> value(threshold.value);
+                conn->async_method_call(
+                    [](const boost::system::error_code &ec) {
+                        if (ec)
+                        {
+                            std::cerr << "Error setting threshold " << ec
+                                      << "\n";
+                        }
+                    },
+                    ENTITY_MANAGER_NAME, path,
+                    "org.freedesktop.DBus.Properties", "Set",
+                    thresholdInterface, "Value", value);
+            },
+            ENTITY_MANAGER_NAME, path, "org.freedesktop.DBus.Properties",
+            "GetAll", thresholdInterface);
+    }
+}
+
+static constexpr std::array<const char *, 4> ATTR_TYPES = {"lcrit", "min",
+                                                           "max", "crit"};
+
+bool ParseThresholdsFromAttr(
+    std::vector<thresholds::Threshold> &threshold_vector,
+    const std::string &input_path, const double scale_factor)
+{
+    for (auto &type : ATTR_TYPES)
+    {
+        auto attr_path = boost::replace_all_copy(input_path, "input", type);
+        std::ifstream attr_file(attr_path);
+        if (!attr_file.good())
+            continue;
+        std::string attr;
+        std::getline(attr_file, attr);
+        attr_file.close();
+
+        Level level;
+        Direction direction;
+        double val = std::stod(attr) / scale_factor;
+        if (type == "min" || type == "max")
+            level = Level::WARNING;
+        else
+            level = Level::CRITICAL;
+        if (type == "min" || type == "lcrit")
+            direction = Direction::LOW;
+        else
+            direction = Direction::HIGH;
+
+        if (DEBUG)
+            std::cout << "Threshold: " << attr_path << ": " << val << "\n";
+
+        threshold_vector.emplace_back(level, direction, val);
+    }
+    // no thresholds is allowed, not an error so return true always
+    return true;
+}
+
+bool HasCriticalInterface(
+    const std::vector<thresholds::Threshold> &threshold_vector)
+{
+    for (auto &threshold : threshold_vector)
+    {
+        if (threshold.level == Level::CRITICAL)
+            return true;
+    }
+    return false;
+}
+
+bool HasWarningInterface(
+    const std::vector<thresholds::Threshold> &threshold_vector)
+{
+    for (auto &threshold : threshold_vector)
+    {
+        if (threshold.level == Level::WARNING)
+            return true;
+    }
+    return false;
+}
+} // namespace thresholds
diff --git a/sensors/src/Utils.cpp b/sensors/src/Utils.cpp
new file mode 100644
index 0000000..6ce3f18
--- /dev/null
+++ b/sensors/src/Utils.cpp
@@ -0,0 +1,165 @@
+/*
+// Copyright (c) 2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include <Utils.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include <experimental/filesystem>
+#include <fstream>
+#include <regex>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/bus/match.hpp>
+
+namespace fs = std::experimental::filesystem;
+const static constexpr char* POWER_INTERFACE_NAME =
+    "xyz.openbmc_project.Chassis.Control.Power";
+const static constexpr char* POWER_OBJECT_NAME =
+    "/xyz/openbmc_project/Chassis/Control/Power0";
+
+bool getSensorConfiguration(
+    const std::string& type,
+    const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
+    ManagedObjectType& resp, bool useCache)
+{
+    static ManagedObjectType managedObj;
+
+    if (!useCache)
+    {
+        managedObj.clear();
+        sdbusplus::message::message getManagedObjects =
+            dbusConnection->new_method_call(
+                ENTITY_MANAGER_NAME, "/", "org.freedesktop.DBus.ObjectManager",
+                "GetManagedObjects");
+        bool err = false;
+        try
+        {
+            sdbusplus::message::message reply =
+                dbusConnection->call(getManagedObjects);
+            err = reply.is_method_error();
+            if (!err)
+            {
+                reply.read(managedObj);
+            }
+        }
+        catch (const sdbusplus::exception::exception&)
+        {
+            err = true;
+        }
+
+        if (err)
+        {
+            std::cerr << "Error communicating to entity manager\n";
+            return false;
+        }
+    }
+    for (const auto& pathPair : managedObj)
+    {
+        std::vector<boost::container::flat_map<std::string, BasicVariantType>>
+            sensorData;
+        bool correctType = false;
+        for (const auto& entry : pathPair.second)
+        {
+            if (boost::starts_with(entry.first, type))
+            {
+                correctType = true;
+                break;
+            }
+        }
+        if (correctType)
+        {
+            resp.emplace(pathPair);
+        }
+    }
+    return true;
+}
+
+bool find_files(const fs::path dir_path, const std::string& match_string,
+                std::vector<fs::path>& found_paths, unsigned int symlink_depth)
+{
+    if (!fs::exists(dir_path))
+        return false;
+
+    fs::directory_iterator end_itr;
+    std::regex search(match_string);
+    std::smatch match;
+    for (auto& p : fs::recursive_directory_iterator(dir_path))
+    {
+        std::string path = p.path().string();
+        if (!is_directory(p))
+        {
+            if (std::regex_search(path, match, search))
+                found_paths.emplace_back(p.path());
+        }
+        // since we're using a recursive iterator, these should only be symlink
+        // dirs
+        else if (symlink_depth)
+        {
+            find_files(p.path(), match_string, found_paths, symlink_depth - 1);
+        }
+    }
+    return true;
+}
+
+// initially returns false, then sets up matches and returns status
+// should be called once first to initialize
+bool isPowerOn(const std::shared_ptr<sdbusplus::asio::connection>& conn)
+{
+    static std::unique_ptr<sdbusplus::bus::match::match> powerMatch = nullptr;
+    static bool powerStatusOn = false;
+
+    if (powerMatch != nullptr)
+    {
+        return powerStatusOn;
+    }
+
+    // create a match for powergood changes, first time do a method call to
+    // return the correct value
+    std::function<void(sdbusplus::message::message & message)> eventHandler =
+        [&powerStatusOn](sdbusplus::message::message& message) {
+            std::string objectName;
+            boost::container::flat_map<std::string,
+                                       sdbusplus::message::variant<int32_t>>
+                values;
+            message.read(objectName, values);
+            auto findPgood = values.find("pgood");
+            if (findPgood != values.end())
+            {
+                powerStatusOn = sdbusplus::message::variant_ns::get<int32_t>(
+                    findPgood->second);
+            }
+        };
+
+    powerMatch = std::make_unique<sdbusplus::bus::match::match>(
+        static_cast<sdbusplus::bus::bus&>(*conn),
+        "type='signal',interface='org.freedesktop.DBus.Properties',path_"
+        "namespace='/xyz/openbmc_project/Chassis/Control/"
+        "power0',arg0='xyz.openbmc_project.Chassis.Control.Power'",
+        eventHandler);
+
+    conn->async_method_call(
+        [&powerStatusOn](boost::system::error_code ec,
+                         const sdbusplus::message::variant<int32_t>& pgood) {
+            if (ec)
+            {
+                std::cerr << "Error getting initial power status\n";
+                return;
+            }
+            powerStatusOn = sdbusplus::message::variant_ns::get<int32_t>(pgood);
+        },
+        POWER_INTERFACE_NAME, POWER_OBJECT_NAME,
+        "org.freedesktop.DBus.Properties", "Get", "pgood");
+
+    return powerStatusOn;
+}
\ No newline at end of file
