Control relay with contact button on Openhab problem - openhab

Hy,
I want to control a relay with a button in openHab, and i want to create a rule to check if state is ON or OFF and after that to do a thing.
I am new in codding and i don't know what I've done wrong.
I need some help, please.
This si the code from home.items
Switch buc1_releu "Bec1" (LivingRoom) { gpio="pin:18 activelow:yes initialValue:high force:true" }
Contact buc1_intrerupator "Intrerupator [%s]" (LivingRoom) { gpio="pin:23 activelow:yes" }
And this si the home.rules
rule "buc1"
when
Item buc1_intrerupator changed
then
if (buc1_releu.state == ON){
sendCommand(OFF)
}
else if (buc1_releu.state == OFF){
sendCommand(ON)
}
end

Found the problem, this is the correct code :D
rule "buc1"
when
Item buc1_intrerupator changed
then
if (buc1_releu.state == ON) {
buc1_releu.sendCommand(OFF)
}
else if (buc1_releu.state == OFF) {
buc1_releu.sendCommand(ON)
}
end

Related

Detect opening of PluginSidebar in Wordpress Gutenberg

I'm looking to reinitialise some settings and state data when my PluginSidebar is reopened, but I'm struggling to find anything useful in wp.data core/editor or similar that I could use to best create a subscription.
Does gutenberg provide any such data where I can check to see if the side panel is open or shut, so that I could fire a function of my choice every time it opens?
At present, I have a mutationObserver in place listening to see if it opens, which is quite clunky.
Some pseudo-code of my preferred approach.
subscribe(() => {
if (select('core/editor').isPluginSidebarOpen()) {
open = true
} else {
open = false
}
})
Your pseudo-code is so very close.. the function exists and is called isPluginSidebarOpened and comes from core/edit-post, eg:
import { subscribe, select } from '#wordpress/data';
subscribe(() => {
if (select('core/edit-post').isPluginSidebarOpened()) {
// Is open..
} else {
// Is closed..
}
});

Prestashop 1.6.1.4 - Add CSS to CMS Page of Module

I am making a module that adds new tab in product edit page. The installation is Prestashop 1.6.1.4. The module adds a tab with some input fields that send data to mysql tables, but what I want to do is to style the fields a little bit, so that they look good. I am adding this in my module.php file:
public function install() {
if ($this->psversion() == 5 || $this->psversion() == 6)
{
if (parent::install() == false or !$this->registerHook('displayHeader') or !$this->registerHook('productFooter') or !$this->registerHook('displayAdminProductsExtra') or !$this->registerHook('actionProductUpdate') or !$this->registerHook('displayBackOfficeHeader'))
{
return false;
}
}
return true;
}
Then below this I put this code:
public function hookDisplayBackOfficeHeader($params) {
$this->context->controller->addCSS($this->_path.'views/css/adminsportsnutritionfadd.css');
}
But can't make the .css file appear. The file is in the right location, it has proper permissions and the owner of the file is www-data:www-data so this shouldn't be a permission issue. I have disable css combining in Prestashop as well as caching. Before reloading the page I am also deleting Prestashop's cache just in case, as well as I am deleting my brower's cache. Can somebody give me a hand in this?
Do like this:
public function hookBackOfficeHeader()
{
$this->context->controller->addCSS($this->_path.'views/css/adminsportsnutritionfadd.css');
}
For me it works like this:
$this->context->controller->addCSS($this->_path . 'views/css/back.css');
So the only difference is the css file name.
Not sure if you got this sorted or not, but...
I use this function within most of my modules to add
jQuery, Font-awesome, CSS & JS, then have it show ONLY on that module page...
public function hookDisplayBackOfficeHeader($params)
{
if(!(Tools::getValue('controller') == 'AdminModules'
&& Tools::getValue('configure') == 'MyModuleName')
){
return;
}
else
{
if ( method_exists($this->context->controller, 'addJquery') )
{
$this->context->controller->addJquery();
$this->context->controller->addCss('//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
$this->context->controller->addCss($this->_path.'views/css/back.css');
$this->context->controller->addJs($this->_path.'views/js/back.js');
}
}
}

HTML Button Clicker Counter Unique Click

I was searching for a simple html code for button clicker counter and I found this site
However, I need the clicks to be anti-spam so I just need a button that allows only one click per IP address.
Help?
Here's the code:
function clickCounter() {
if(typeof(Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount)+1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "" + localStorage.clickcount + " people are going!";
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
<body>
<p><button onclick="clickCounter()" type="button">I'M GOING!</button></p>
<div id="result"></div>
Here is a guy who posted a long list of different free ip lookup services which all return JSON objects of the requester. Depending on your back-end you can use this information and store which ip addresses have already clicked the button. This way is also more secure since localStorage stores the data in the users browser, they could just clear that data and click again.

set a number of click and disable link from click after hit the target number

I need to do setting for wordpress which set a number of clicks for some link to disable it after hit the targeted number. Is there any plugin or suggest to do so?
You can do it with a simple jQuery:
$('#targetLink').click(function () {
$('#counter').html(function (i, val) {
if (val > 1) {
return val * 1 - 1;
} else {
$("#targetLink").removeAttr("href");
if (val > 0) {
return val * 1 - 1;
}
}
}); });
Demo: http://jsfiddle.net/533L9n5f/
Of course, you have to adapt it to your HTML structure.
Next time, it could help a lot if you elaborate your question a bit more. Read this site for some best practices: How do I ask a good question?

How to prevent navigating to another page in meteor iron router

I have a form page and I want to alert user if he leaves it without saving the form.
Typically I can achieve this purpose by stating a function window.onBeforeUnload.
window.onBeforeUnload = function(){return 'Please save the form before navigating';}
But it seems doesn't work in my project using Meteor and Iron Router.
Any suggestion?
This is maybe a hacky version, but it works:
isUnsaved = ->
return unless #ready()
unless confirm 'Do you really want to leave the page?'
Router.go(#url)
Router.onStop isUnsaved,
only: [
'editPost'
]
Old post, but just solved it. Here is my solution :
Router.route('/myPath', {
unload: function (e, obj) {
if(Session.get("hasChanged")){
if (confirm("Are you sure you want to navigate away ?")) {
// Go and do some action
}else{
// Redirect to itself : nothing happend
this.redirect('/myPath');
}
}
}
}

Resources