Giter Site home page Giter Site logo

Comments (6)

sweetpi avatar sweetpi commented on July 23, 2024

Hi,
cool, it would be nice if you could share your code. For the temperature sensor you must emit a "temperature" event and let the getTemperature function return the current temperature (in a promise).

You could for example emit a temperature event every 5 seconds:

class YourTemperatureSensor extends env.devices.TemperatureSensor
  temperature: null

  constructor: (@config) ->
    # update the temperature every 5 seconds
    setInterval( =>
      @doYourStuff()
    , 5000
    )

  doYourStuff: (values) ->
    # temperature = ...
    @temperature = temperature
    @emit "temperature", temperature

  getTemperature: -> Q(@temperature)

Create the Temperature Device like the switch. If you need further help, just ask.

from pimatic-plugin-template.

gadgethome avatar gadgethome commented on July 23, 2024

Thanks for reply. Not sure how to start with it. Do I need to create a new file using the above code or add it to an existing file?

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

Its your choice. I would add it to the same. You can look at the pilight plugin for an example: https://github.com/pimatic/pimatic-pilight/blob/master/pilight.coffee#L214-L225

from pimatic-plugin-template.

gadgethome avatar gadgethome commented on July 23, 2024

Still trying to do my first test one using the example of

class YourTemperatureSensor extends env.devices.TemperatureSensor
temperature: null

constructor: (@config) ->
# update the temperature every 5 seconds
setInterval( =>
@doYourStuff()
, 5000
)

doYourStuff: (values) ->
# temperature = ...
@temperature = temperature
@emit "temperature", temperature

getTemperature: -> Q(@temperature)

but getting the following error and not sure which device ID its referring to. Any suggestions?

info: loading plugin: "plugin-template"...
info: loading plugin: "rest-api"...
info: loading plugin: "mobile-frontend"...
info: socket.io: socket.io started

/home/pi/pimatic-dev/node_modules/pimatic/node_modules/q/q.js:126
throw e;
^
AssertionError: the device has no id
at MySwitch.Device (/home/pi/pimatic-dev/node_modules/pimatic/lib/devices.coffee:46:16)
at MySwitch.Sensor (/home/pi/pimatic-dev/node_modules/pimatic/lib/devices.coffee:192:20)
at MySwitch.TemperatureSensor (/home/pi/pimatic-dev/node_modules/pimatic/lib/devices.coffee:199:7)
at new MySwitch (/home/pi/pimatic-dev/node_modules/pimatic-plugin-template/my-plugin.coffee:81:5)
at MyPlugin.createDevice (/home/pi/pimatic-dev/node_modules/pimatic-plugin-template/my-plugin.coffee:66:7)
at MyPlugin.createDevice (/home/pi/pimatic-dev/node_modules/pimatic-plugin-template/my-plugin.coffee:11:1)
at Framework.loadDevices (/home/pi/pimatic-dev/node_modules/pimatic/lib/framework.coffee:231:9)
at loadPlugins.then.then.then.then.then.then.context.waitFor (/home/pi/pimatic-dev/node_modules/pimatic/lib/framework.coffee:437:24)
at _fulfilled (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/q/q.js:759:13)
at /home/pi/pimatic-dev/node_modules/pimatic/node_modules/q/q.js:573:44
at flush (/home/pi/pimatic-dev/node_modules/pimatic/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:902:3

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

Could you please use Syntax Highlighting/code blocks in your post?

from pimatic-plugin-template.

sweetpi avatar sweetpi commented on July 23, 2024

You must set a id and name property like in the switch device for your YourTemperatureSensor in the constructor function:

@name = "some name or from config"
@id = "some-id"

from pimatic-plugin-template.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.