How do I use my project (code) in Node RED?

I want to use Node RED to control the Tasmota device that will turn on the heater. In Poland, where I come from, electricity is cheaper at certain hours and days and I want to use it. I wrote a project in Typescript (GitHub - wachcio/cheap-electricity-tariff: The program shows whether there is a cheap electricity tariff now or at a given time and date.) and would like to use it with NodeRED. The function result isCheapTariff = ( dateTime: Date | Dayjs = new Date(), tariff: Tariff = Tariff.Energa_G12W, ): boolean would control the heater. What's the easiest way to do this?

Not sure what exactly that you are asking.

Are you wanting to find a way to enable a Boolean payload to control a tasmota device using node-RED?

If so, that can be done via MQTT.
If not, can you describe in more detail exactly what help that you would like.

Assuming that you produce a valid package (the package.json doesn't appear to correctly define the main entry point at present since you need a js output not ts and you've defined the package as an ECMA module instead of a CommonJS module), you can simply require it and assign to a global variable in settings.js. Alternatively, you can add it to a function node.

I just have a problem with proper conversion to JS and importing in NodeRED

so you want to change the heating depending on whether or not the electricity is cheap or expensive, rather then turn on when at a specific temp, or are you trying to control your heat as well.
I do not use boolean I use on or off in my mqtt message to my tasmota device.
This is for cooling a fermenter , but hopefully gives you an idea.

[{"id":"06ea2d4d1d36cae0","type":"switch","z":"f6858fe416b029b9","name":"","property":"target","propertyType":"flow","rules":[{"t":"gte","v":"ambient","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":974.9296836853027,"y":182.63451766967773,"wires":[["f59a64501d3e4995","b757ad2e9a21172d"],["dca9643d538d9c10","efbd0245b8dd1ad5"]]},{"id":"b757ad2e9a21172d","type":"debug","z":"f6858fe416b029b9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1130.926254272461,"y":148.74212837219238,"wires":[]},{"id":"f59a64501d3e4995","type":"change","z":"f6858fe416b029b9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1152.926368713379,"y":183.62065601348877,"wires":[["8e8ffc3b58648b48","be56299a7516053c"]]},{"id":"dca9643d538d9c10","type":"change","z":"f6858fe416b029b9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1153.926368713379,"y":220.6223258972168,"wires":[["e4614f962524aec5","be56299a7516053c"]]},{"id":"efbd0245b8dd1ad5","type":"debug","z":"f6858fe416b029b9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1121.92626953125,"y":252.74561882019043,"wires":[]},{"id":"8e8ffc3b58648b48","type":"debug","z":"f6858fe416b029b9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1321.9333801269531,"y":152.74212837219238,"wires":[]},{"id":"be56299a7516053c","type":"change","z":"f6858fe416b029b9","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"cmnd/Wferm/POWER","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1333.0086555480957,"y":199.00171947479248,"wires":[["0cf85aaa0a7b0507"]]},{"id":"e4614f962524aec5","type":"debug","z":"f6858fe416b029b9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1323.9279975891113,"y":256.74909019470215,"wires":[]},{"id":"0cf85aaa0a7b0507","type":"mqtt out","z":"f6858fe416b029b9","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"31a99116.50a74e","x":1481.0086784362793,"y":199.0017604827881,"wires":[]},{"id":"31a99116.50a74e","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]

the switch node in that example I had set guidlines. in the switch node you may need to enter your parameters, how ever your are needing something with dates and times as well.

also check this out for heating.

communication with a tasmota device is done with mqtt. Also if the status of the electricity is on a web page looking into html nodes and see if you can just have it queried in and convert data into the information you need.
If you have a flow started and are stuck,
share the flow with us so we can try to help you out.
make sure you follow these guidelines when sharing a flow.

have you looked here?
http://www.howtocreate.co.uk/tutorials/jsexamples/syntax/prepareInline.html
this is how to covert regular text into Javascript

I have established MQTT communication with my Tasmota device (relay device).
Now I'm trying to make an NPM bundle out of my TypeScript project with GitHub - tomchen/example-typescript-package: Example TypeScript Package ready to be published on npm & Tutorial / Instruction / Workflow for 2021 so I can add it to NodeRED. It is supposed to return 'true' or 'false' and then using MQTT I want to send it to the device

I was able to build the NPM library.
I set it up in the "functionGlobalContext" section of the NodeRED setup.
Then using "global.get" I used it in a function and send the result (boolean) via MQTT to the Tasmot device.
Everything works ok :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.