Comments (6)
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.
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.
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.
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.
Could you please use Syntax Highlighting/code blocks in your post?
from pimatic-plugin-template.
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)
- How to debug actions? HOT 6
- Help with pimatic-ifttt
- How to generate documentation? HOT 1
- problems using the new matcher HOT 14
- inAnyOrder for the matcher HOT 4
- Template file needs renaming HOT 1
- Template error - ReferenceError: conf is not defined HOT 2
- multiple filebrowser settings? HOT 2
- Retrieving device details from json HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pimatic-plugin-template.